Java || Beats 100% || Bit Manipulation
Complexity
Time complexity: O(log N)

Space complexity:O(1)
Code


# Complexity
- Time complexity: O(log N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int bitwiseComplement(int n) {
        if(n==0){
            return 1;
        }
        int ans = 0;
        int i = 0;
        while(n>0){
            if((n&1) != 1){
                ans = (ans ^ (1<<i));
            }
            n >>= 1;
            i++;
        }
        return ans;
    }
}
```
['Java']