您的位置:首页 > 其它

【LeetCode】 504. Base 7

2017-08-29 14:13 423 查看
Given an integer, return its base 7 string representation.

Example 1:

Input: 100

Output: “202”

Example 2:

Input: -7

Output: “-10”

题目就是转换为7进制的数字。

class Solution {
public:
string convertToBase7(int num) {
string s;
int fla=0;
if(num<0){
num=-num;
fla=1;
}
if(num==0)s="0";
while(num){
s=to_string(num%7)+s;
num/=7;
}
if(fla)s='-'+s;
return s;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode