2 lines Python


  • 0

    Pretty straight forward one, as long as we have enough different kinds, we return n//2.

    class Solution(object):
        def distributeCandies(self, candies):
            """
            :type candies: List[int]
            :rtype: int
            """
            n, kinds = len(candies), len(set(candies))
            return n//2 if kinds*2 >= n else kinds
    

Log in to reply
 

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