https://school.programmers.co.kr/learn/courses/30/lessons/138476
import java.util.*;
class tan implements Comparable<tan>{
int size;
int cnt;
tan(int size, int cnt)
{
this.size = size;
this.cnt = cnt;
}
@Override
public int compareTo(tan o)
{
return Integer.compare(this.cnt, o.cnt);
}
}
class Solution {
public int solution(int k, int[] tangerine) {
int answer = 0;
Queue<tan> que = new PriorityQueue<>(Collections.reverseOrder());
HashMap<Integer, Integer> map = new HashMap<>();
for(int i : tangerine)
{
map.put(i, map.getOrDefault(i, 0)+1);
}
Set<Integer> keys = map.keySet();
for(int key : keys)
{
que.add(new tan(key, map.get(key)));
}
int curcnt = 0;
while(curcnt < k)
{
tan cur = que.poll();
curcnt += cur.cnt;
answer++;
}
return answer;
}
}