コーディングテストはもっと辛くて問題に答える


Programmer the mapped(level 2)解答
import heapq

def solution(scoville, k):
  heapq.heapify(scoville)
  cnt = 0
  while(True):
    first = heapq.heappop(scoville)
    if first >= k:
      break
    else:
      if len(scoville) == 0:
        return -1
    second = heapq.heappop(scoville)
    result = first+(second*2)
    heapq.heappush(scoville, result)
    cnt += 1

  return cnt
第2級にとって、これは非常に簡単な問題です.
お尻を知っているかどうか聞きたいだけです.
リストをお尻にする方法を学びました