1-line JavaScript O(n) solution using Set


  • 2
    var distributeCandies = function(candies) {
        return Math.min(new Set(candies).size, candies.length / 2);
    };
    

Log in to reply
 

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