Skip to content

Instantly share code, notes, and snippets.

@wanderindev
Created July 2, 2022 15:20
Show Gist options
  • Save wanderindev/24ccdd83fa035be22896c0337f9ce824 to your computer and use it in GitHub Desktop.
Save wanderindev/24ccdd83fa035be22896c0337f9ce824 to your computer and use it in GitHub Desktop.
class Solution:
def contains_duplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
checked_values = set()
for num in nums:
if num in checked_values:
return True
checked_values.add(num)
return False
# Test cases
sol = Solution()
nums = [1, 2, 3, 1]
assert sol.contains_duplicate(nums)
nums = [1, 2, 3, 4]
assert not sol.contains_duplicate(nums)
nums = [1, 1, 1, 3, 3, 4, 3, 2, 4, 2]
assert sol.contains_duplicate(nums)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment