您的位置:首页 > 其它

leetcode 504. Base 7

2017-03-09 16:14 281 查看
public class Solution {
public String convertToBase7(int num) {
if (num == 0)
return "0";
String res = "";
int temp = num;
int remainder =  temp % 7;
while (temp!=0) {
res = String.valueOf(Math.abs(remainder)) + res;
temp /= 7;
remainder = temp % 7;
}

if (num < 0 )
res = "-" + res;
return res;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: