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 class Solution {
public String convertToTitle(int n) {
String s = "";
while(n>0) {
s = (char)((n - 1) % 26 + 'A') + s; //因为1match的是A,所以要n-1
n = (n - 1) / 26; //数字转char只要加上(char)就好了
}
return s;
}
}