504. Base 7 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]. 思路:辗转相除法.…
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]. 给一个整数,返回它的七进制数. 解法1: 迭代 解法2: 递归 Java: public class Solu…
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]. 不停除以7, 然后把余数放到ans里面, 最后reverse ans加上符号即可. Code class Sol…
题目: 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]. 分析: 给定一个7进制数,求十进制表示,注意返回的是字符串. 进制转换没什么好说的,注意这道题测试用例是…
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]. class Solution(object): def convertToBase7(self, num): &…
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]. 解题:题意很容易理解,将十进制整型数转化为七进制的数,并以字符串的形式返回.先看我写的第一种方法,比较繁琐,也利…