特殊情况得多考虑一下
class Solution {
public String convertToBase7(int num) {
if(num == 0) {
return "0";
}
int temp = num;
StringBuilder sb = new StringBuilder();
while(temp != 0) {
sb.append(Math.abs(temp % 7));
temp /= 7;
}
if(num < 0) {
sb.append("-");
}
return sb.reverse().toString();
}
}