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빨 오지네
'Programing > 자료구조, Algorithm' 카테고리의 다른 글
BaekJoon - 10773:제로 (0) | 2020.10.30 |
---|---|
programmers - 소수찾기[level1] - python (에라토스테네스의 체) (0) | 2020.08.27 |
programmers - 올바른괄호[level2] - python (0) | 2019.01.26 |
programmers - 주식가격[level2] - python (0) | 2019.01.26 |
programmers - 스킬트리[level2] - python (0) | 2019.01.25 |