Skip to content

Commit 83e0596

Browse files
authored
Update 137-single-number-ii.js
1 parent 933191a commit 83e0596

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

137-single-number-ii.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,18 @@ const singleNumber = function(nums) {
1313
if(hash[el] === 1) return +el
1414
}
1515
};
16+
17+
// another
18+
19+
/**
20+
* @param {number[]} nums
21+
* @return {number}
22+
*/
23+
const singleNumber = (nums)=> {
24+
let one=0, two=0;
25+
for (let i=0; i<nums.length; i++) {
26+
one = (one ^ nums[i]) & ~two;
27+
two = (two ^ nums[i]) & ~one;
28+
}
29+
return one;
30+
}

0 commit comments

Comments
 (0)