Given an integer, return its base 7 string representation.
Example 1:
Input: 100 Output: "202"
Example 2:
Input: -7 Output: "-10"
Note: The input will be in range of [-1e7, 1e7].
def convertToBase(num):
sign = '' if num >= 0 else '-'
nums = abs(num)
ans = 0
while num >= 7:
res,mod = divmod(num,7)
ans.append(str(res))
ans.append(str(num))
return sign + ''.join(reversed(ans))