일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Decorator
- 파이썬
- 운영체제
- Generator
- 30. Substring with Concatenation of All Words
- 시바견
- kaggle
- 프로그래머스
- LeetCode
- Regular Expression
- Python
- DWG
- concurrency
- Convert Sorted List to Binary Search Tree
- 109. Convert Sorted List to Binary Search Tree
- Class
- Python Implementation
- 715. Range Module
- Substring with Concatenation of All Words
- 컴퓨터의 구조
- shiba
- attribute
- 315. Count of Smaller Numbers After Self
- t1
- 43. Multiply Strings
- 밴픽
- data science
- Python Code
- iterator
- Protocol
Archives
- Today
- Total
Scribbling
프로그래머스: 더 맵게 본문
import heapq
import copy
def solution(scoville, K):
answer = 0
h = copy.deepcopy(scoville)
heapq.heapify(h)
while len(h) >= 2 and h[0] < K:
f1 = heapq.heappop(h)
f2 = heapq.heappop(h)
heapq.heappush(h, (f1+2*f2))
answer += 1
if h[0] >= K:
return answer
else:
return -1
'Computer Science > Coding Test' 카테고리의 다른 글
프로그래머스: 이중 우선 순위 큐 (0) | 2021.10.16 |
---|---|
프로그래머스: 디스크 컨트롤러 (0) | 2021.10.16 |
프로그래머스: 주식 가격 (0) | 2021.10.16 |
프로그래머스: 다리를 지나는 트럭 (0) | 2021.10.15 |
LeetCode: 96. Unique Binary Search Trees (0) | 2021.10.13 |