Do you need hash table? A simple explanation without hashtable

  • 0
    class Solution(object):
        def distributeCandies(self, candies):
            :type candies: List[int]
            :rtype: int
            if candies :
                kinds = set(candies)
                m  = len(kinds) # number of kinds available
                n  = len(candies) // 2 # number of candies to be given to sister
                if m <= n:
                    # if number of candies that sister can have exceed number of kinds
                    # she can have all possible kinds of candies
                    return m
                    # if there're are more kinds than number of candies sister can have 
                    # then she can have at most n kinds of candies
                    return n
            return 0

Log in to reply

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