Created
July 2, 2022 15:20
-
-
Save wanderindev/24ccdd83fa035be22896c0337f9ce824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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