class Solution(object):
def convertToBase7(self, num):
"""
:type num: int
:rtype: str
"""
res= ""
flag = 0
if num == 0:
return "0"
if num<0:
flag= 1
num=-num
while num:
res+=str(num%7)
num=num/7
if flag == 1:
return "-"+res[::-1]
return res[::-1]
LeetCode Base 7
最新推荐文章于 2024-02-17 11:22:42 发布