Skip to content

Commit 37a1466

Browse files
committed
[PGS] 귤 고르기 / Level 2 / 33분 (성공)
1 parent 1a96998 commit 37a1466

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def solution(k, tangerine):
2+
answer = 0
3+
4+
'''
5+
딕셔너리에 key크기, value 개수를 저장한다.
6+
딕셔너리를 value를 크기가 큰 순으로 정렬한다.
7+
'''
8+
box = {}
9+
for t in tangerine:
10+
if t in box:
11+
box[t] += 1
12+
else:
13+
box[t] = 1
14+
15+
box = dict(sorted(box.items(), key=lambda x: x[1], reverse=True))
16+
17+
'''
18+
k에 개수 값을 빼가고, 뺄 때마다 answer+=1한다.
19+
k가 0보다 작아지면 바로 answer return한다
20+
'''
21+
for size in box:
22+
if k <= 0:
23+
return answer
24+
k -= box[size]
25+
answer += 1
26+
return answer

0 commit comments

Comments
 (0)