[leetcode-504-Base 7]】的更多相关文章

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进制数,求十进制表示,注意返回的是字符串. 进制转换没什么好说的,注意这道题测试用例是…
C#版 - Leetcode 504. 七进制数 - 题解 Leetcode 504. Base 7 在线提交: https://leetcode.com/problems/base-7/ 题目描述 给定一个整数,将其转化为7进制,并以字符串形式输出. 示例 1: 输入: 100 输出: "202" 示例 2: 输入: -7 输出: "-10" 注意: 输入范围是 [-1e7, 1e7] .   ●  题目难度: 简单 通过次数:707 提交次数:1.8K 贡献者:…
problem 504. Base 7 solution: class Solution { public: string convertToBase7(int num) { ) "; string ans = ""; int number = abs(num); ) { ans = to_string(number%) + ans; number /= ; } ) ans = "-" + ans; return ans; } }; 参考 1. Leetc…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 内建库 BigInteger类 逐位计算 倍数相加 日期 题目地址:https://leetcode.com/problems/base-7/#/description 题目描述 Given an integer, return its base 7 string representation. Example 1: Input: 100 Outpu…
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]. 解题:题意很容易理解,将十进制整型数转化为七进制的数,并以字符串的形式返回.先看我写的第一种方法,比较繁琐,也利…
给定一个整数,将其转化为7进制,并以字符串形式输出.示例 1:输入: 100输出: "202" 示例 2:输入: -7输出: "-10"注意: 输入范围是 [-1e7, 1e7] .详见:https://leetcode.com/problems/base-7/description/ C++: class Solution { public: string convertToBase7(int num) { if(num==0) { return "0&…