Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created March 17, 2019 10:03
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 fpdjsns/a2f5812d1218065e20539f6cab6843ee to your computer and use it in GitHub Desktop.
Save fpdjsns/a2f5812d1218065e20539f6cab6843ee to your computer and use it in GitHub Desktop.
[leetcode] 1012. Complement of Base 10 Integer : https://leetcode.com/problems/complement-of-base-10-integer/
class Solution {
public:
int bitwiseComplement(int N) {
if(N == 0) return 1;
int tmp = 1;
int answer = 0;
while(0 < N){
answer += ((N + 1) % 2) * tmp;
N /= 2;
tmp *= 2;
}
return answer;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment