[Java/C++/Python] Find 111.....1111 >= N
Hints\n1. what is the relationship between input and output\n2. input + output = 111....11 in binary format\n3. Is there any corner case?\n4. 0 is a corner case
## **Hints**\n1. what is the relationship between input and output\n2. input + output = 111....11 in binary format\n3. Is there any corner case?\n4. 0 is a corner case expecting 1, output > input\n\n\n## **Intuition**\nLet\'s find the first number `X` that `X = 1111....1 > N`\nAnd also, it has to be noticed that,\n`N = 0` is a corner case expecting`1` as result.\n\n<br>\n\n## **Solution 1**:\n`N + bitwiseComplement(N) = 11....11 = X`\nThen `bitwiseComplement(N) = X - N`\n\n**Java:**\n```\n    public int bitwiseComplement(int N) {\n        int X = 1;\n        while (N > X) X = X * 2 + 1;\n        return X - N;\n    }\n```\n\n**C++:**\n```\n    int bitwiseComplement(int N) {\n        int X = 1;\n        while (N > X) X = X * 2 + 1;\n        return X - N;\n    }\n```\n\n**Python:**\n```\n    def bitwiseComplement(self, N):\n        X = 1\n        while N > X: X = X * 2 + 1\n        return X - N\n```\n<br>\n\n## **Solution 2**:\n`N ^ bitwiseComplement(N) = 11....11 = X`\n`bitwiseComplement(N) = N ^ X`\n\n**Java:**\n```\n    public int bitwiseComplement(int N) {\n        int X = 1;\n        while (N > X) X = X * 2 + 1;\n        return N ^ X;\n    }\n```\n\n**C++:**\n```\n    int bitwiseComplement(int N) {\n        int X = 1;\n        while (N > X) X = X * 2 + 1;\n        return N ^ X;\n    }\n```\n\n**Python:**\n```\n    def bitwiseComplement(self, N):\n        X = 1\n        while N > X: X = X * 2 + 1;\n        return N ^ X\n```\n<br>\n\n## **Complexity**\n`O(logN)` Time\n`O(1)` Space\n<br>\n\n## Python 1-lines\nUse `bin`\n```\n    def bitwiseComplement(self, N):\n        return (1 << len(bin(N)) >> 2) - N - 1\n```\nUse `translate`\n```\n    def bitwiseComplement(self, N):\n        return int(bin(N)[2:].translate(string.maketrans(\'01\', \'10\')), 2)\n```
[]