Java O(1) | 1 line Solution
I find the length of binary representation. For example, for 5 it will base-2 is "101" and length of this String is 3. \n2. Then by doing 1 << 3, I will have "1
1. I find the length of binary representation. For example, for 5 it will base-2 is "101" and length of this String is 3. \n2. Then by doing 1 << 3, I will have "1000" which 8 in base-10. \n3. Then I do 8 - 1 = 7, which is "111" in base-2.\n4. By applying XOR operation I will have "101" XOR "111" = "010", which is 2 in base-10.\n\n# Code\n```\nclass Solution {\n    public int bitwiseComplement(int n) {\n        return n ^ ((1 << Integer.toBinaryString(n).length()) - 1);\n    }\n}\n```
['Java']