DeepRest

Complement of Base 10 Integer

Jan 4th, 2022 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. class Solution:
  2.     def bitwiseComplement(self, n: int) -> int:
  3.         mask = 2
  4.         while mask <= n:
  5.             mask <<= 1
  6.         #return mask - 1 - n
  7.         return (mask - 1) ^ n
  8.         '''if n == 0:
  9.            return 1
  10.        bits = int(log(n, 2)) + 1
  11.        return n ^ ((1<<bits) - 1)'''
  12.  
Add Comment
Please, Sign In to add comment