uploaded at 2022. 12. 16. 오후 8:42:47

This commit is contained in:
rl544
2022-12-16 20:42:48 +09:00
parent e1ddeb4fd4
commit 169d3e6aa7
+16
View File
@@ -0,0 +1,16 @@
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/1845
import java.util.HashMap;
class Solution {
public int solution(int[] nums) {
int answer = 0;
HashMap<Integer, Integer> hash = new HashMap<>();
for(int a : nums){
hash.put(a,hash.getOrDefault(a,0)+1);
}
for(Integer b : hash.keySet()){
answer += 1;
}
return (answer > nums.length/2) ? nums.length/2 : answer;
}
}