Contains Duplicate

Array
Easy

Approach

Diagrams

Analysis

Time

O(n)

Space

O(n)
class Solution:
    def containsDuplicate(self, nums):

        numsAlreadySeen = set()

        for num in nums:
            isDuplicate = num in numsAlreadySeen

            if isDuplicate:
                return True

            numsAlreadySeen.add(num)

        return False

Learn

#Hash Set

Videos