Python solution. Beats 80%


  • -3
    P
    class Solution(object):
        def containsDuplicate(self, nums):
            """
            :type nums: List[int]
            :rtype: bool
            """
            if len(nums)==0:
                return False
            numbers=set()
            numbers.update(nums)
            if len(numbers)==len(nums):
                return False
            else:
                return True

  • -5

    return not (len(nums) == len(set(nums)))
    和第一个人一样的思想,但是人家的额代码更加的简洁明了,只用了一行搞定,真是神奇啊


Log in to reply
 

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