We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 189e032 commit 54cfc2fCopy full SHA for 54cfc2f
LeetCode/476.number-complement.cpp
@@ -0,0 +1,9 @@
1
+class Solution {
2
+public:
3
+ int bitwiseComplement(int n) {
4
+ if(n == 0) return 1;
5
+ int numberOfBits = log2(n) + 1; // 100 log10(100) => 2+1 => 3
6
+ int mask = (1 << numberOfBits) - 1; // pow(2, numberOfBits)
7
+ return mask ^ n;
8
+ }
9
+};
0 commit comments