leetcode-easy-array-217. Contains Duplicate

mycode  76.39%

class Solution(object):
    def containsDuplicate(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        if len(nums) == 0 or len(nums) == 1:
            return False
        return not (len(set(nums)) == len(nums))

参考  

最快:

class Solution(object):
    def containsDuplicate(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        hasht = {}
        for num in nums:
            if num not in hasht:
                hasht[num] = True
            else:
                return True
        return False

猜你喜欢

转载自www.cnblogs.com/rosyYY/p/10984973.html