[LeetCode]504. Base 7
题目
Given an integer, return its base 7 string representation.
Example 1:
1 | Input: 100 |
Example 2:
1 | Input: -7 |
Note: The input will be in range of [-1e7, 1e7].
难度
Easy
方法
对num取除以7的余数,即为最低位的数,然后将num/7赋值给num,继续取num除以7的余数即为倒数第二位的数,依次类推。注意num为0时需要返回"0"
python代码
1 | class Solution(object): |