Skip to content

Commit 668e036

Browse files
authored
Create 476. Number Complement (#564)
2 parents 52ccb14 + 6c23556 commit 668e036

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

476. Number Complement

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution {
2+
public:
3+
int findComplement(int num) {
4+
int shift = (log10(num) / log10(2)) + 1;
5+
int mask = -1 << shift;
6+
mask ^= -1;
7+
return mask ^ num;
8+
}
9+
};

0 commit comments

Comments
 (0)