Python set - 36ms, O(n)


  • 4
    P
    class Solution(object):
        def containsDuplicate(self, nums):
            s = set()
            for num in nums:
                if num in s: return True
                else: s.add(num)
            return False

  • 0
    L

    class Solution(object):
    def containsDuplicate(self, nums):
    s = set()
    for num in nums:
    if num in s: return True
    else: s.add(num)
    return False


Log in to reply
 

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