Skip to content

Commit 702faa4

Browse files
authored
Create Contains Duplicate.py
1 parent 7e942ae commit 702faa4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Contains Duplicate.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'''
2+
Given an array of integers, find if the array contains any duplicates.
3+
4+
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
5+
6+
Example 1:
7+
8+
Input: [1,2,3,1]
9+
Output: true
10+
Example 2:
11+
12+
Input: [1,2,3,4]
13+
Output: false
14+
Example 3:
15+
16+
Input: [1,1,1,3,3,4,3,2,4,2]
17+
Output: true
18+
'''
19+
20+
class Solution(object):
21+
def containsDuplicate(self, nums):
22+
"""
23+
:type nums: List[int]
24+
:rtype: bool
25+
"""
26+
box = set()
27+
for num in nums:
28+
if num in box:
29+
return True
30+
box.add(num)
31+
32+
return False

0 commit comments

Comments
 (0)