Java 8 Solution: Using Stream


  • 1
    C
    public class Solution {
        public int distributeCandies(int[] candies) {
            int len = candies.length;
            int max = (int)Arrays.stream(candies).distinct().count();
            return Math.min(max, len/2);
        }
    }
    

    This solution utilize stream() and distinct() method


Log in to reply
 

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