LeetCode Solutions
1009. Complement of Base 10 Integer
Time: Space:
class Solution {
public:
int bitwiseComplement(int N) {
int mask = 1;
while (mask < N)
mask = (mask << 1) + 1;
return mask ^ N;
}
};
class Solution {
public int bitwiseComplement(int N) {
int mask = 1;
while (mask < N)
mask = (mask << 1) + 1;
return mask ^ N;
}
}
class Solution:
def bitwiseComplement(self, N: int) -> int:
mask = 1
while mask < N:
mask = (mask << 1) + 1
return mask ^ N