6 lines Python solution with explanation


  • 1
    T

    Python solution:

    class Solution(object):
        def distributeCandies(self, candies):
            amt = len(candies)/2
            s = set(candies)
            if len(s) < amt:
                return len(s)
            else:
                return amt
    
    1. Find the number of candies that each child can get
    2. Find how many kinds of candies there are
    3. Return whichever is smaller

Log in to reply
 

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