Java HashSet Solution


  • 0
    public int distributeCandies(int[] candies) {
            int n=candies.length;
            Set<Integer> set=new HashSet<>();
            for(int num:candies) set.add(num);
            if(set.size()>=n/2) return n/2;
            return set.size();
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.