LeetCode 504. Base 7 (C++)
题目:
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进制数,求十进制表示,注意返回的是字符串。
进制转换没什么好说的,注意这道题测试用例是有负数的,且返回值是字符串,记得转成字符串形式。
程序:
class Solution {
public:
string convertToBase7(int num) {
if(num == ) return "";
string res;
int n = abs(num);
while(n){
res = to_string(n%) + res;
n /= ;
}
if(num < )
return "-"+res;
else
return res;
}
};
LeetCode 504. Base 7 (C++)的更多相关文章
- 45. leetcode 504. Base 7
504. Base 7 Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: ...
- [LeetCode] 504. Base 7 基数七
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- [LeetCode] 504. Base 7_Easy tag: Math
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- C#版 - Leetcode 504. 七进制数 - 题解
C#版 - Leetcode 504. 七进制数 - 题解 Leetcode 504. Base 7 在线提交: https://leetcode.com/problems/base-7/ 题目描述 ...
- 【leetcode】504. Base 7
problem 504. Base 7 solution: class Solution { public: string convertToBase7(int num) { ) "; st ...
- 【LeetCode】504. Base 7 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 内建库 BigInteger类 逐位计算 倍数相加 ...
- [LeetCode&Python] Problem 504. Base 7
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- 504. Base 7
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- 504 Base 7 七进制数
给定一个整数,将其转化为7进制,并以字符串形式输出.示例 1:输入: 100输出: "202" 示例 2:输入: -7输出: "-10"注意: 输入范围是 [- ...
随机推荐
- Docker 安装 - Docker 与前端(一)
Docker 是一个开源的容器引擎,可以方便的对容器进行管理.作为一种新兴的虚拟化方式,跟传统的虚拟化方式相比具有众多优势.<Docker 遇见前端>系列文章,旨在记录如何通过 docke ...
- 13.2SolrCloud集群使用手册之CoreAdmin API
转载请出自出处:http://www.cnblogs.com/hd3013779515/ CoreAdminHandler是用来管理Solr cores的,用来管理一个Solr instance中所有 ...
- python第三十四课——2.匿名函数配合容器函数的使用
匿名函数配合容器函数的使用(了解) 1.匿名函数配合列表对象使用 lt=[lambda x:x**2,lambda x:x**3,lambda x:x**4] for i in lt: print(i ...
- Linq EF 添加数据执行事务处理
在EF4.1的DBContext中实现事务处理(BeginTransaction)和直接执行SQL语句的示例 2012-12-12 10:39 5538人阅读 ...
- WorldWind源码剖析系列:外包围盒类BoundingBox和外包围球类BoundingSphere
PluginSDK中的外包围盒.外包围球分别用类 BoundingBox和BoundingSphere描述,其类图如下所示. 外包围盒BoundingBox类的corners字段用来存储外包围盒的8个 ...
- JS数字格式化(用逗号隔开 代码已做了修改 支持0-9位逗号隔开)
最近做项目需要我们前端对金额进行千分位格式化(也就是说每三位用逗号隔开),代码已经做了修改 之前的版本是本人疏忽 真对不住大家了!现在已经做了修改 如果还有不完善的地方 请大家多多指教! 1. 支持 ...
- javaee_SSH
这是javaee课程的第六个实验ssh sturts2+sping 3+hibernate 现予以记录整个过程,以防遗忘 1. 2. 3. 4. 5.输入mvnrepository.com进入-> ...
- China Cloud Computing Conference(2018.07.24)
时间:2018.07.24地点:北京国家会议中心
- Python3入门(七)——模块
在Python中,一个.py文件就称之为一个模块(Module).(例如main.py就称之为main模块) 为了避免模块名冲突,Python又引入了按目录来组织模块的方法,称为包(Package). ...
- 20155308《网络攻防》 Exp1 PC平台逆向破解(5)M
20155308<网络攻防> Exp1 PC平台逆向破解(5)M 逆向及Bof基础实践说明 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是 ...