✅ One Line Solution
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: O(1). Space complexi
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: $$O(1)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n    def findComplement(self, v: int) -> int:\n        return v^2**v.bit_length()-1\n```\n\n# Code #2\nTime complexity: $$O(1)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n    def findComplement(self, v: int) -> int:\n        return v^(2<<int(log2(v)))-1\n```\nSeen [here](https://leetcode.com/problems/number-complement/solutions/96026/python-4-ways)\n\n# Code #3\nTime complexity: $$O(1)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n    def findComplement(self, v: int) -> int:\n        return ~v+2**len(f\'{v:b}\')\n```\nSeen [here](https://leetcode.com/problems/number-complement/solutions/3896397/Python.-One-line-solution./comments/2586149)\n\n# Code #4\nTime complexity: $$O(1)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n    def findComplement(self, v: int) -> int:\n        return v^int(\'1\'*v.bit_length(),2)\n```\n\n# Code #5\nTime complexity: $$O(1)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n    def findComplement(self, v: int) -> int:\n        return int(re.sub(\'(.)\',lambda m:\'01\'[m[1]<\'1\'],f\'{v:b}\'),2)\n```\n\n# Code #6\nTime complexity: $$O(1)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n    def findComplement(self, v: int) -> int:\n        return int(f\'{v:b}\'.replace(\'0\',\'.\').replace(\'1\',\'0\').replace(\'.\',\'1\'),2)\n```
['Bit Manipulation', 'Python', 'Python3']