Java 8 one line solution O(n)


  • 3
    L
    public class Solution {
        public int distributeCandies(int[] candies) {
            return Math.min(candies.length / 2, IntStream.of(candies).boxed().collect(Collectors.toSet()).size());
        }
    }
    

  • 0
    B

    Nice and clean solution! Thanks


Log in to reply
 

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