leetcode1012

 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

 

上一篇:Weekly Contest 129


下一篇:CF1204E Natasha, Sasha and the Prefix Sums