섬연결하기
-
[🥲 프로그래머스] 섬 연결하기 - 그리디 알고리즘Algorithm/1일 1코테 2021. 8. 10. 23:02
https://programmers.co.kr/learn/courses/30/lessons/42861 코딩테스트 연습 - 섬 연결하기 4 [[0,1,1],[0,2,2],[1,2,5],[1,3,1],[2,3,8]] 4 programmers.co.kr 나의 풀이 def solution(n, costs): costs.sort(key=lambda x:x[2]) # 비용이 작은 순대로 정렬 all_island = [i for i in range(n)] # 모든 섬 answer = 0 now = costs.pop(0) # 맨 처음 costs를 뺀다 while all_island: cur_island = now[0] # 현재섬 next_island = now[1] # 다음섬 answer += now[2] # 비용 답..