顿搜
飞过闲红千叶,夕岸在哪
类目归类
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
public String convertToTitle(int n) {
StringBuilder sb = new StringBuilder();
while (n > 0) {
sb.insert(0, (char) ((n - 1) % 26 + 'A'));
n = (n - 1) / 26;
}
return sb.toString();
}public class LeetCode0168 {
public String convertToTitle(int n) {
StringBuilder sb = new StringBuilder();
while (n > 0) {
sb.insert(0, (char) ((n - 1) % 26 + 'A'));
n = (n - 1) / 26;
}
return sb.toString();
}
public static void main(String[] args) {
LeetCode0168 leetcode = new LeetCode0168();
System.out.println(leetcode.convertToTitle(2147483647));
}
}