[Baekjoon] 1932. 정수 삼각형
·
코딩테스트/Python
🔗 Problem Link 1932번: 정수 삼각형 첫째 줄에 삼각형의 크기 n(1 ≤ n ≤ 500)이 주어지고, 둘째 줄부터 n+1번째 줄까지 정수 삼각형이 주어진다. www.acmicpc.net ❔Thinking 정수로 이루어진 삼각형에서, 위에서 큰 수를 선택해 더해 내려와 얻게되는 가장 큰 수를 반환한다. 왼쪽 대각선 아래, 오른쪽 대각선 아래의 수만 선택하여 더할 수 있다. 💻Solution 1. 위에서 내려오는 방법 import copy n = int(input()) graph = [[]] for i in range(n): graph.append(list(map(int, input().split()))) dp = copy.deepcopy(graph) for i in range(1, n): f..
[Baekjoon] 18352. 특정 거리의 도시 찾기
·
코딩테스트/Python
🔗 Problem Link 18352번: 특정 거리의 도시 찾기 첫째 줄에 도시의 개수 N, 도로의 개수 M, 거리 정보 K, 출발 도시의 번호 X가 주어진다. (2 ≤ N ≤ 300,000, 1 ≤ M ≤ 1,000,000, 1 ≤ K ≤ 300,000, 1 ≤ X ≤ N) 둘째 줄부터 M개의 줄에 걸쳐서 두 개 www.acmicpc.net ❔Thinking 도시의 개수, 도로의 개수, 출발 도시의 번호가 주어질 때, 최단 거리가 k인 도시를 모두 출력한다. 💻Solution 1. BFS를 활용한 풀이 from collections import deque import sys input = sys.stdin.readline n, m, k, x = map(int, input().split()) graph ..
[Programmers] Level 2. 조건별로 분류하여 주문상태 출력하기
·
코딩테스트/MySQL
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking FOOD_ORDER에서 5월 1일을 기준의 주문ID, 제품ID, 출고일자, 출고 여부를 반환한다. 💻Solution SELECT ORDER_ID, PRODUCT_ID, DATE_FORMAT(OUT_DATE, '%Y-%m-%d') AS 'OUT_DATE', CASE WHEN OUT_DATE > '2022-05-01' THEN '출고대기' WHEN OUT_DATE
[Programmers] Level 2. 두 큐 합 같게 만들기
·
코딩테스트/Python
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking 같은 크기의 두 큐가 주어지면, 두 큐의 합이 같도록 만드는 최소 방법을 구하여 반환한다. 💻Solution from collections import deque def solution(queue1, queue2): q1_sum, q2_sum = sum(queue1), sum(queue2) queue1, queue2 = deque(queue1), deque(queue2) cnt = 0 while (queue1 and queue2) and cnt != len(queu..
[Leetcode] 77. Combinations
·
코딩테스트/Python
🔗 Problem Link Combinations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 1부터 n까지의 숫자들 가운데 k개를 뽑아 조합한 결과를 반환한다. 💻Solution 1. 조합을 활용한 풀이 from itertools import combinations def combine(self, n: int, k: int): n_list = [i for i in range(1,n+1)] return list(combinations(n_..
[Leetcode] 46. Permutations
·
코딩테스트/Python
🔗 Problem Link Permutations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 주어진 숫자들을 모두 활용해 만들 수 있는 수열을 리스트에 담아 반환한다. 💻Solution 1. 조합을 활용한 풀이 from itertools import permutations def permute(self, nums): return list(permutations(nums, len(nums))) 2. DFS를 활용한 풀이 - 반복문 def ..