Java 3-liner O(n) Time O(n) Space


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

Log in to reply
 

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