Skip to content

Commit 995512b

Browse files
committed
feat: single-number
1 parent ae5e363 commit 995512b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arr.single-number.py

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

0 commit comments

Comments
 (0)