2025-08-01 18:34:49 +0000 UTC

Complement of Base 10 Integer

Code

class Solution:
    def bitwiseComplement(self, n: int) -> int:
        if n == 0:
            return 1
        res, count = 0, 0
        while n > 0:
            if n & 1 == 0:
                res += 2 ** count
            count += 1
            n >>= 1
        return res