Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created July 25, 2023 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkucmierz/2cfc361fc75c5c30f9bb8499bfa907c1 to your computer and use it in GitHub Desktop.
Save gkucmierz/2cfc361fc75c5c30f9bb8499bfa907c1 to your computer and use it in GitHub Desktop.
single_number.js
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