Last active
August 22, 2023 17:56
-
-
Save youngvctr/69f32a24009e96afe5439e34c570ea55 to your computer and use it in GitHub Desktop.
Programmers | 귤 고르기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://school.programmers.co.kr/learn/courses/30/lessons/138476