Skip to content

Commit 1c2fea1

Browse files
committed
add 136, 217
1 parent d83d7fc commit 1c2fea1

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

136. Single Number.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/26 17:52
3+
# @Author : xulzee
4+
5+
# @File : 136. Single Number.py
6+
# @Software: PyCharm
7+
8+
from typing import List
9+
10+
11+
class Solution:
12+
def singleNumber(self, nums: List[int]) -> int:
13+
a = 0
14+
for i in nums:
15+
a ^= i
16+
return a
17+
18+
if __name__ == '__main__':
19+
A = [4,1,2,1,2]
20+
print(Solution().singleNumber(A))

217. Contains Duplicate.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/26 17:02
3+
# @Author : xulzee
4+
5+
# @File : 217. Contains Duplicate.py
6+
# @Software: PyCharm
7+
from typing import List
8+
9+
10+
class Solution:
11+
def containsDuplicate1(self, nums: List[int]) -> bool:
12+
if len(nums) == len(set(nums)):
13+
return False
14+
else:
15+
return True
16+
17+
def containsDuplicate(self, nums: List[int]) -> bool:
18+
A = set()
19+
for i in nums:
20+
if i not in A:
21+
A.add(i)
22+
else:
23+
return True
24+
return False
25+
26+
if __name__ == '__main__':
27+
A = [1, 2, 3, 3, 4, 5, 6, 7]
28+
print(Solution().containsDuplicate(A))
29+

0 commit comments

Comments
 (0)