Skip to content

Instantly share code, notes, and snippets.

@youngvctr
Last active August 22, 2023 17:56
Show Gist options
  • Save youngvctr/69f32a24009e96afe5439e34c570ea55 to your computer and use it in GitHub Desktop.
Save youngvctr/69f32a24009e96afe5439e34c570ea55 to your computer and use it in GitHub Desktop.
Programmers | 귤 고르기
import java.util.*;
class Solution {
public int solution(int k, int[] tangerine) {
int answer = 0;
Map<Integer, Integer> map = new HashMap<>();
for(int size:tangerine){
map.put(size, map.getOrDefault(size, 0) + 1);
}
List<Integer> temp = new ArrayList<>(map.values());
Collections.sort(temp, Collections.reverseOrder());
int totalTangerine = 0;
for(int i=0; i<temp.size(); i++){
if(totalTangerine < k){
totalTangerine += temp.get(i);
answer++;
}
}
return answer;
}
}
@youngvctr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment