feat(1070_convert-to-base-2): add py3 soln
This commit is contained in:
15
1070_convert-to-base-2/python3/solution.py
Normal file
15
1070_convert-to-base-2/python3/solution.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class Solution:
|
||||
def baseNeg2(self, n: int) -> str:
|
||||
result = ''
|
||||
|
||||
while n != 0:
|
||||
rem = n % -2
|
||||
n = n // -2
|
||||
|
||||
if rem < 0:
|
||||
n += 1
|
||||
rem += 2
|
||||
|
||||
result = str(rem) + result
|
||||
|
||||
return result if result != '' else '0'
|
||||
Reference in New Issue
Block a user