study/Algorithm

[프로그래머스/Java] 폰켓몬

으녕오리 2025. 3. 10. 13:29

문제

 

나의 풀이

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);
    }
}