Skip to content

Instantly share code, notes, and snippets.

@muzea
Created July 4, 2019 02:37
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 muzea/a50a68397bb6936cb48d7e13d9a69f60 to your computer and use it in GitHub Desktop.
Save muzea/a50a68397bb6936cb48d7e13d9a69f60 to your computer and use it in GitHub Desktop.
Single Number II
class Solution {
public:
int singleNumber(vector<int>& nums) {
auto it = nums.begin(),end = nums.end();
int o = 0,t = 0;
while(it != end){
int oo = o;
o = (o^(*it))&(~(t&*it));
t = (~(t&(*it))) & (oo & (*it) | t);
++it;
}
return o;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment