Solution
C++ []\nclass Solution {\n public:\n  int bitwiseComplement(int N) {\n    int mask = 1;\n\n    while (mask < N)\n      mask = (mask << 1) + 1;\n\n    return mas
```C++ []\nclass Solution {\n public:\n  int bitwiseComplement(int N) {\n    int mask = 1;\n\n    while (mask < N)\n      mask = (mask << 1) + 1;\n\n    return mask ^ N;\n  }\n};\n```\n\n```Python3 []\nclass Solution:\n    def bitwiseComplement(self, n: int) -> int:\n        cnt=0\n        ans=0\n        if n==0:\n            return 1\n        while n>0:\n            if n&1:\n                cnt+=1\n            else:\n                ans =ans +(2**cnt)\n                cnt+=1\n            n=n>>1\n        return ans\n```\n\n```Java []\nclass Solution {\n    public int bitwiseComplement(int n) {\n        if(n == 0) return 1;\n        int res = 0;\n        int fac = 1;\n        \n        while(n != 0){\n            res += fac * (n % 2 == 0 ? 1 : 0);\n            fac *= 2;\n            n /= 2;\n        }\n        return res;\n    }\n}\n```
['C++', 'Java', 'Python3']