C# solution, two lines


  • 0
    L
        public int DistributeCandies(int[] candies) {
            HashSet<int> lhs = new HashSet<int>( candies );
            return Math.Min( lhs.Count,  ( candies.Length >> 1 ));
        }
    

  • 0
    L

    one line:

        public int DistributeCandies(int[] candies) {
            return Math.Min( candies.Distinct<int>().Count<int>(),  ( candies.Length >> 1 ));
        }
    

Log in to reply
 

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