Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def baseNeg2(self, N: int) -> str:
- base = -2
- res = []
- while N:
- rem = N % base
- if rem < 0:
- rem -= base
- N = N // base + 1
- else:
- N = N // base
- res.append(str(rem))
- return ''.join(res[::-1]) if res else "0"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement