476. Number Complement
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : August 22, 2024
Last updated : August 22, 2024
Related Topics : Bit Manipulation
Acceptance Rate : 70.29 %
class Solution:
def findComplement(self, num: int) -> int:
num = list(bin(num))
mp = ['1', '0']
for i, c in enumerate(num[2:], 2) :
num[i] = mp[ord(c) - ord('0')]
return int(''.join(num), 2)