feat(0504_base-7): add py3 soln

This commit is contained in:
2022-04-11 12:59:55 +05:30
parent 2348097dd3
commit 74770ca9b1
2 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
class Solution:
def convertToBase7(self, num: int) -> str:
sign = '-' if num < 0 else ''
num = abs(num)
b7 = ''
while num > 0:
b7 = str(num % 7) + b7
num //= 7
return '0' if b7 == '' else sign + b7