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.
2 parents 41d9f6f + 28256c4 commit 031e04bCopy full SHA for 031e04b
260. Single Number III.js
@@ -0,0 +1,34 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number[]}
4
+ */
5
+var singleNumber = function(nums) {
6
+ if(nums === null || nums.length <= 2) {
7
+ return nums;
8
+ }
9
+
10
+ var xor = nums[0];
11
+ for(var i = 1; i < nums.length; i++) {
12
+ xor ^= nums[i];
13
14
15
+ var exp = 1;
16
+ while(!(exp & xor)) {
17
+ exp = exp * 2;
18
19
+ console.log(exp);
20
+ var xorBit0 = 0;
21
+ var xorBit1 = 0;
22
23
+ for(var j = 0; j < nums.length; j++) {
24
+ if(exp & nums[j]){
25
+ xorBit1 ^= nums[j];
26
+ console.log("with 1: " + nums[j]);
27
+ } else {
28
+ console.log("with 0: " + nums[j]);
29
+ xorBit0 ^= nums[j];
30
31
32
33
+ return [xorBit0, xorBit1];
34
+};
0 commit comments