Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
思路:可以看做是一个十进制到二十六进制的转换问题。
public String convertToTitle(int n) {
if (n <= 0) {
return "";
}
StringBuilder res = new StringBuilder();
while (n > 0) {
n--;
int mode = n % 26;
res.insert(0, (char)('A' + mode));
n /= 26;
}
return res.toString();
}