We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1cfc7e9 commit 145834dCopy full SHA for 145834d
medium/.DS_Store
0 Bytes
medium/array/56-i數組出現的次數.py
@@ -0,0 +1,28 @@
1
+# 全部xor找到第一個1,做分組,0的1組,1的一組
2
+
3
+class Solution:
4
+ def singleNumbers(self, nums):
5
+ x = 0
6
+ for i in nums:
7
+ x ^= i
8
+ start = 0
9
+ while x:
10
+ if not (x & 1):
11
+ start += 1
12
+ x >>= 1
13
+ else:
14
+ break
15
+ a = 0
16
+ b = 0
17
18
+ if (i >> start) & 1:
19
+ a ^= i
20
21
+ b ^= i
22
+ return [a, b]
23
+'''
24
+if __name__ == '__main__':
25
+ sol = Solution()
26
+ nums = [1, 2, 5, 2]
27
+ print (sol.singleNumbers(nums))
28
0 commit comments