우선순위 큐 활용
import heapq
def solution(k, score):
answer = []
klist = []
for s in score:
if len(klist) >= k:
heapq.heappushpop(klist, s)
else:
heapq.heappush(klist, s)
minnum = klist[0]
answer.append(minnum)
return answer
'언어' 카테고리의 다른 글
2016 (1) | 2023.12.15 |
---|---|
콜라 (0) | 2023.12.15 |
leetcode (1) (1) | 2023.12.15 |
'문자열 내 마음대로 정렬하기' (0) | 2023.12.13 |
완전탐색 (0) | 2023.12.13 |