Skip to content

Commit 98713af

Browse files
authored
[20251021] PGM / LV2 / 귤 고르기 / 강신지
1 parent 408c446 commit 98713af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int k, int[] tangerine) {
6+
int answer = 0;
7+
Map<Integer, Integer> count = new HashMap<>();
8+
9+
for (int i : tangerine){
10+
count.put(i, count.getOrDefault(i, 0)+1);
11+
}
12+
13+
List<Integer> countList = new ArrayList<>();
14+
15+
for (int i : count.values()){
16+
countList.add(i);
17+
}
18+
19+
Collections.sort(countList, Collections.reverseOrder());
20+
21+
int sum = 0;
22+
for (int i : countList){
23+
sum += i;
24+
answer++;
25+
if (sum >= k){
26+
return answer;
27+
}
28+
}
29+
return answer;
30+
}
31+
}
32+
```

0 commit comments

Comments
 (0)