class Solution {
public String convertToBase7(int num) {
if (num == 0) {
return "0";
}
int isNegative = 0;
if (num < 0) {
num = -num;
isNegative = 1;
}
StringBuffer sb = new StringBuffer();
while (num > 0) {
sb.append(num % 7);
num /= 7;
}
if (isNegative == 1) {
sb.append('-');
}
return sb.reverse().toString();
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交