描述
Given an integer, return its base 7 string representation.
Example 1:
1 2
| Input: 100 Output: "202"
|
Example 2:
1 2
| Input: 100 Output: "202"
|
Note : The input will be in range of [-1e7, 1e7].
分析
类似的问题做过很多吧。
解决方案1(Python)
1 2 3 4 5 6 7 8 9 10 11
| class Solution(object): def convertToBase7(self, num): """ :type num: int :rtype: str """ if num < 0: return '-' + self.convertToBase7(-num) if num < 7: return str(num) return self.convertToBase7(num/7) + str(num%7)
|
相关问题