Skip to content

Commit 291f956

Browse files
authored
[20251216] PGM / Lv2 / 귤 고르기 / 이강현
1 parent f0999b4 commit 291f956

File tree

1 file changed

+23
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)