-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathContainsDupicate.py
45 lines (38 loc) · 963 Bytes
/
ContainsDupicate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coding: utf-8
__author__ = 'devin'
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
d = dict()
for val in nums:
if val in d.keys():
return True
d[val] = 1
return False
def containsDuplicate1(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
data = set(nums)
if len(data)-len(nums) < 0:
return True
return False
def containsDuplicate2(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
data_len = len(nums)
for i in range(data_len):
for j in range(i+1,data_len):
if nums[i] == nums[j]:
return True
return False
if __name__ == '__main__':
s = Solution()
dd = [1, 2, 3]
print s.containsDuplicate2(dd)