Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def bitwiseComplement(self, n: int) -> int:
- mask = 2
- while mask <= n:
- mask <<= 1
- #return mask - 1 - n
- return (mask - 1) ^ n
- '''if n == 0:
- return 1
- bits = int(log(n, 2)) + 1
- return n ^ ((1<<bits) - 1)'''
Add Comment
Please, Sign In to add comment