[Java/Python] Easy One Line
Chinese explanation on youtube and bilibili\n\n## Explanation\nInspired by @wen_han, I\'d like to share this solution.\nFirst we find a big number x with its bi
Chinese explanation on [youtube](http://https://www.youtube.com/watch?v=0MBC7y_j80A) and [bilibili](https://www.bilibili.com/video/av51966587/)\n\n## Explanation\nInspired by @wen_han, I\'d like to share this solution.\nFirst we find a big number `x` with its binary value `10101...10101`\n`x` needs to be bigger than `10^9` so it can cover all input `N`.\n\nHere I choose `mask = 2^32 / 3 = 1431655765` and we have `mask > 10^9`\n\nThe `01` pattern binary number have 2 special characters:\n1. Because it has 0 on all even bits, which are negative bits in base -2, \nit has same value in base 2 and base -2.\n2. When we bitwise operation `mask ^ x`, we will change some 1 to 0 on odd position,\nand change some 0to 1 on even position. \nIn the view of base -2, we actually `mask - x`.\nSo `mask ^ x` in base 2 is same as `mask - x` in base -2.\n\nTake advantage of this observation:\n`mask ^ (mask - x)` in base 2 is same as `mask - (mask - x) = x` in base -2.\nSo we get the result of this problem.\n<br>\n\n## Example\n`N = 3` has reault `00111` in base -2.\n\n`N = 3          = 00011`\n`mask = 21      = 10101`\n`mask - N = 18  = 10010`\n`mask ^ (mask - N) = 00111`\n<br>\n\n## Complexity\n`1431655765 ^ (1431655765 - N)` is `O(1)`\nTransform of binary string,\nI\'ll say `O(1)` for small integer,\n`O(logN)` for big number.\n<br>\n\n**Java:**\n```java\n    public String base2(int N) {\n        return Integer.toBinaryString(1431655765 ^ (1431655765 - N));\n    }\n```\n\n**Python:**\n```pyton\n    def baseNeg2(self, N):\n        return bin(1431655765 ^ (1431655765 - N))[2:]\n```\n
[]