Created
July 25, 2023 02:56
-
-
Save gkucmierz/2cfc361fc75c5c30f9bb8499bfa907c1 to your computer and use it in GitHub Desktop.
single_number.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const singleNumber = nums => { | |
let ones = 0; | |
let twos = 0; | |
let notThrees = 0; | |
for (let n of nums) { | |
twos |= (ones & n); | |
ones ^= n; | |
notThrees = ~(ones & twos); | |
ones &= notThrees; | |
twos &= notThrees; | |
} | |
return ones; | |
}; | |
singleNumber([0,1,0,1,0,1,99]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment