Python 2 Approach 97.96% beats
If you got help from this,... Plz Upvote .. it encourage me\n# EXAMPLE , \n        # N = 101  (5)\n        # MASK WILL BE  111 (7)\n        # COMPLEMENT MASK - 
**If you got help from this,... Plz Upvote .. it encourage me**\n# EXAMPLE , \n        # N = 101  (5)\n        # MASK WILL BE  111 (7)\n        # COMPLEMENT MASK - N = 7-5 = 2 (010)\n# Code\n```\n<!-- 1ST APPROACH -->\nclass Solution:\n    def bitwiseComplement(self, n: int) -> int:\n       \n        if n == 0:\n            return 1\n\n        mask = 0\n        m = n\n        while m != 0:\n            mask = mask << 1 | 1\n            m = m >> 1\n        \n        return mask - n\n        # OR\n        #return (~n) & mask \n\n<!-- ============================================================ -->\n<!-- 2ND APPROACH -->\nclass Solution:\n    def bitwiseComplement(self, n: int) -> int:\n        x = 1\n        while n > x:\n            x = x * 2 + 1\n        return x - n\n```
['Bit Manipulation', 'Python', 'Python3']