class Solution {
public String convertToBase7(int n) {
boolean ok = true ;
String ans = "";
if (n == 0 ) {
ans = "0";
return ans;
}
if (n < 0) {
ok = false;
n = Math.abs(n);
}
while(n > 0) {
int cur = n%7;
n = n/7;
ans = cur + ans;
}
if (ok == false) {
ans = "-" + ans;
}
return ans;
}
}
效率低