Skip to content

Commit 61250cf

Browse files
committed
Update single-number-iii.py
1 parent a67b79c commit 61250cf

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Python/single-number-iii.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
#
1818

1919
class Solution:
20+
# @param {integer[]} nums
21+
# @return {integer[]}
22+
def singleNumber(self, nums):
23+
x_xor_y = reduce(operator.xor, nums)
24+
x_xor_y &= -x_xor_y
25+
result = [0, 0]
26+
for i in nums:
27+
result[not i & x_xor_y] ^= i
28+
return result
29+
30+
class Solution2:
2031
# @param {integer[]} nums
2132
# @return {integer[]}
2233
def singleNumber(self, nums):
@@ -31,4 +42,4 @@ def singleNumber(self, nums):
3142
if i & bit:
3243
x ^= i
3344

34-
return [x, x_xor_y ^ x]
45+
return [x, x ^ x_xor_y]

0 commit comments

Comments
 (0)