Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def findComplement(self, num):
- i=1
- while i<=num:
- i = i << 1
- return (i-1)^num
- # num: 5 = 101;
- # i=1, after i<<1: shift left, i=10;
- # i=100,i=1000; now i>num;
- # 1000-1= 111; 111^101= 010 got it!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement