Skip to content

Commit 69c6ae1

Browse files
authored
Create complement-of-base-10-integer.cpp
1 parent 553a939 commit 69c6ae1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

C++/complement-of-base-10-integer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(logn)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int bitwiseComplement(int N) {
7+
int X = 1;
8+
while (N > X) {
9+
X = X * 2 + 1;
10+
}
11+
return X - N;
12+
}
13+
};

0 commit comments

Comments
 (0)