Skip to content

Commit fcfad3c

Browse files
committedDec 24, 2020
feat: single-number-ii
1 parent 995512b commit fcfad3c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 

‎arr.single-number-ii.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""
6+
137. 只出现一次的数字 II
7+
https://leetcode-cn.com/problems/single-number-ii/
8+
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次。找出那个只出现了一次的元素。
9+
"""
10+
def singleNumber(self, nums: List[int]) -> int:
11+
tmp_map = {}
12+
for num in nums:
13+
tmp_map[num] = tmp_map.get(num, 0) + 1
14+
15+
for k, v in tmp_map.items():
16+
if v == 1:
17+
return k
18+
19+
return 0
20+
21+
22+
23+
so = Solution()
24+
print(so.singleNumber([0,1,0,1,0,1,99]))

0 commit comments

Comments
 (0)
Please sign in to comment.