Explained | Easy to understand | Faster than 99.58% | Simple | Bit manipulation | Python Solution
Later I found that this solution correponds to the second approach mentioned in the solution\n\nHere, in this soution, we are just making another bit variable t
##### Later I found that this solution correponds to the second approach mentioned in the solution\n\nHere, in this soution, we are just making another bit variable to be full of 1\'s upto the length of bits in num and then simply returning the XOR of two\nnum = 5 = 101\nbit ===== 111\nAns ==== 010 = 2\n\n```\ndef findComplement(self, num: int) -> int:\n        bit = 0\n        todo = num\n        while todo:\n            bit = bit << 1\n            bit = bit ^ 1\n            todo = todo >> 1\n        return bit ^ num\n```\n\n**I hope that you\'ve found the solution useful.**\n*In that case, please do upvote and encourage me to on my quest to document all leetcode problems\uD83D\uDE03*\nPS: Search for **mrmagician** tag in the discussion, if I have solved it, You will find it there\uD83D\uDE38
['Bit Manipulation', 'Python', 'Python3']