public class Solution { //runtime = 171ms
public String convertToTitle(int n) {
StringBuilder s =new StringBuilder();
char ch[] = new char[50];
if (n <= 0){
return "Error!";
}
int i = 0;
while (n > 0){
if (n % 26 == 0){
n = n - 1;
ch[i] = (char) (n % 26 + 65);
}
else{
ch[i] = (char) (n % 26 + 64);
}
n /= 26;
i ++;
}
i = 0;
while (ch[i] != '\0'){
i ++;
}
while (i > 0){
s.append(ch[i - 1]);
i --;
}
return s.toString();
}
}
Excel Sheet Column Title
最新推荐文章于 2019-05-03 19:37:47 发布