Skip to content

Commit 4e88c68

Browse files
committed
Time: 2 ms (42.58%), Space: 6 MB (30.84%) - LeetHub
1 parent c2a2c3e commit 4e88c68

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

1009-complement-of-base-10-integer/1009-complement-of-base-10-integer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
class Solution {
22
public:
33
int bitwiseComplement(int n) {
4+
45
int m = n;
56
int mask = 0;
7+
8+
// Exception case
69
if (n == 0)
710
return 1;
11+
812
while(m!=0)
913
{
1014
mask = (mask << 1) | 1;
1115
m = m >> 1;
1216
}
17+
1318
int ans = (~n) & mask;
1419
return ans;
1520
}

0 commit comments

Comments
 (0)