Skip to content

Commit 007a0cc

Browse files
committed
1 parent feb52ea commit 007a0cc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Hongjoo/lv1/명예의전당_1.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
- 명예 전당 : k=3 인 queue : <-| |<-
3+
# 탐색
4+
1. 현재 score = score[i]
5+
2. 명예 전당 업데이트
6+
7+
if len(deque) >= k (꽉참)
8+
=> popleft() &insert
9+
3.발표 점수 = min(deque)
10+
"""
11+
from collections import deque
12+
def solution(k, score):
13+
answer = []
14+
top_k = []
15+
for i in range(len(score)) :
16+
if len(top_k) >= k : # 꽉참
17+
#업데이트 가능 여부 확인
18+
if score[i] > top_k[0] :
19+
del top_k[0] #pop
20+
top_k.append(score[i])
21+
# print(f"apdate {score[i]}=> { top_k}")
22+
23+
else : # 여유 남음
24+
top_k.append(score[i])
25+
26+
top_k = sorted(top_k) #오름차순
27+
answer.append(top_k[0])
28+
# print(f"{i} - {score[i]}: {top_k}=> {answer}")
29+
return answer

0 commit comments

Comments
 (0)