Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- mysql
- query history
- ksql
- 윈도우
- 동적 차트
- dbt_project
- airflow
- 크롤링
- 파이썬
- numpartitions
- 도커
- CDC
- polars
- DBT
- docker
- freshness
- Materializations
- spring boot
- Python
- k9s
- kafka
- 쿠버네티스
- 모바일
- Java
- 카프카
- KubernetesPodOperator
- proerty
- bar cahrt
- UI for kafka
- spark
Archives
- Today
- Total
데이터 엔지니어 이것저것
더 맵게 (python) 본문
728x90
import heapq
def solution(scoville, K):
answer = 0
heap = []
for i in scoville:
heapq.heappush(heap, i)
while True:
if heap[0] >= K:
return answer
try:
heapq.heappush(heap, heapq.heappop(heap) + (heapq.heappop(heap) * 2))
answer += 1
if heap[0] >= K:
return answer
except:
return -1
여러곳에서 문제가 생겼지만 하나씩 해결했다.
1. heapq를 사용하지 않으니 효율성 검사에서 실패,,,
2. 바로 pass 하는경우
3. 멍청하게도 heap[0] >= K인것을 >로만 하여서 계속 실패,ㅡ,,,
4. 그 외 그냥 try문으로 해버렸다...
728x90
'기타 > 알고리즘' 카테고리의 다른 글
미로찾기 + 길막기 (0) | 2021.06.13 |
---|---|
DFS 알고리즘 (0) | 2020.09.02 |
H-Index (python) (0) | 2020.08.27 |
가장큰수 (python) (0) | 2020.08.24 |
모의고사 (완전탐색 알고리즘, python) (0) | 2020.08.04 |