Advertisement
serega1112

1017

Jan 13th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. class Solution:
  2.     def baseNeg2(self, N: int) -> str:
  3.        
  4.         base = -2
  5.         res = []
  6.         while N:
  7.             rem = N % base
  8.             if rem < 0:
  9.                 rem -= base
  10.                 N = N // base + 1
  11.             else:
  12.                 N = N // base
  13.             res.append(str(rem))
  14.        
  15.         return ''.join(res[::-1]) if res else "0"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement