Data Engineering/Python14 [코테] 프로그래머스 - 길 찾기 게임 Python 코드 import syssys.setrecursionlimit(10**6) # 재귀 횟수 최대 100만으로 증가def solution(nodeinfo): class Node: def __init__(self, num, x, y): self.num = num self.x = x self.y = y self.left = None self.right = None def insertNode(parent, child): if child.x 2025. 10. 25. [코테] 프로그래머스 - 매출 하락 최소화 Python 코드 def solution(sales, links): sales = [0] + sales # idx 시작을 1로 맞춰줌 link = [[] for _ in range(len(sales))] # link[i]: i번 노드의 자식 노드들 dp = [[0, 0] for _ in range(len(sales))] # dp[i][0]: 본인 참석 O, dp[i][1]: 본인 참석 X for parent, child in links: link[parent].append(child) # 노드 순회하면서 dp 값 구하기 def solve(i): # 리프 노드이면 if len(link[i]) == .. 2025. 10. 23. [코테] 프로그래머스 - 양과 늑대 Python 코드 def solution(info, edges): info = [1 if x == 0 else -1 for x in info] # 1: 양, -1: 늑대 graph = [set() for _ in range(len(info))] # i번 노드에서 갈 수 있는 노드들 for [p, c] in edges: graph[p].add(c) def visit(node, info, graph, sumCnt, sheepCnt, nextNodes): if sumCnt + info[node] == 0: # 양, 늑대 수가 같으면 방문 종료 return sumCnt += info[node] if info[nod.. 2025. 10. 17. [코테] 프로그래머스 - 합승 택시 요금 Python 코드 import heapq# 무한INF = float('inf')# start부터 각 지점(1~n)까지 최소 요금 구하기def dijkstra(n, graph, start): dist = [INF]*(n+1) # start 에서 각 지점까지의 최소 요금 hq = [(0, start)] # (비용, 노드번호) 튜플을 담을 최소 힙 (우선순위 큐. 비용순) while hq: fare, node = heapq.heappop(hq) # 이미 저장되어 있는 최단 요금보다 크면 pass if dist[node] 2025. 10. 16. [코테] 프로그래머스 - 베스트앨범 Python 코드 def solution(genres, plays): counts = {} # key: 장르, value: 총 재생횟수 for i in range(len(genres)): counts[genres[i]] = counts.get(genres[i], 0) + plays[i] counts = sorted(counts.items(), key=lambda x: x[1], reverse=True) answer = [] for i in range(len(counts)): # 제일 많이 들은 장르부터, 장르의 개수만큼 반복 idx1, idx2 = -1, -1 # 베스트1, 베스트2 곡의 인덱스 for idx in range(len(g.. 2025. 10. 15. 이전 1 2 3 다음