Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 782 Bytes

_476. Number Complement.md

File metadata and controls

38 lines (25 loc) · 782 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : August 22, 2024

Last updated : August 22, 2024


Related Topics : Bit Manipulation

Acceptance Rate : 70.29 %


Solutions

Python

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)