1 class Solution:
 2     def bitwiseComplement(self, N: int) -> int:
 3         if N==0:
 4             return 1
 5         elif N==1:
 6             return 0
 7 
 8         s = list()
 9         while N!=0:
10             re = N%2
11             if re==0:
12                 re=1
13             else:
14                 re = 0
15             s.append(re)
16             N=N//2
17         sums = 0
18         for i in range(len(s)):
19             cur = int(s[i])
20             cur = cur * pow(2,i)
21             sums +=cur
22         return sums

 

posted on 2019-03-17 13:29  Sempron2800+  阅读(144)  评论(0编辑  收藏  举报