HTMLify
Q1009_Complement_of_Base_10_Integer.py
Views: 528 | Author: djdj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | def bitwiseComplement(self, num): if num==0: return 1 s = [] while num > 0: r = str(num % 2) s.append(r) num = num // 2 s = s[::-1] b = "".join(d for d in s) x = b.replace('0', '2').replace('1', '0').replace('2', '1') sum=0 i=0 x = int(x) while(x>0): r1 = x % 10 m = r1 * pow(2,i) i = i+1 x = x // 10 sum = sum + m return sum |