Programing/자료구조, Algorithm
programmers - 더맵게[level2] - python
r00t0k
2019. 1. 26. 03:46
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import heapq def solution(scoville, K): answer = 0 scoville.sort() scoville = [scoville[i] for i in range(0, len(scoville)) if scoville[i] <= K] try: while 1: if scoville[0] <= K: heapq.heappush(scoville, heapq.heappop(scoville) + (heapq.heappop(scoville) * 2)) answer += 1 else: break except: return -1 return answer | cs |
요약: python빨 오지네