Contains Duplicate
Question
Given an array of integers, write an algorithm to determine whether the array contains any duplicates.
Example 1
Input: [1,2,3,4,5,5]
Output: True
Solution
- ▭
- ▯
all//Contains Duplicate.py
def contains_duplicates(arr):
seen = set()
for elem in arr:
if elem in seen:
return True
seen.add(elem)
return False
result = contains_duplicates([1, 2, 3, 4, 5, 5])
print(result)
all//Contains Duplicate.py
def contains_duplicates(arr):
seen = set()
for elem in arr:
if elem in seen:
return True
seen.add(elem)
return False
result = contains_duplicates([1, 2, 3, 4, 5, 5])
print(result)