Java 8 API 1 line solution (no Hash Map)


  • 0

    Count all distinct kinds of candies and decide how many of them can be given to a sister:

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

Log in to reply
 

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