문제

나의 풀이
import java.util.HashSet;
class Solution {
public int solution(int[] nums) {
HashSet<Integer> set = new HashSet<>();
for (int num : nums) {
set.add(num);
}
int max = nums.length / 2;
return Math.min(set.size(), max);
}
}
'study > Algorithm' 카테고리의 다른 글
| [프로그래머스/Java] x만큼 간격이 있는 n개의 숫자 (0) | 2025.03.12 |
|---|---|
| [프로그래머스/Java] 짝수의 합 (0) | 2025.02.20 |