给定一个正整数,返回它在 Excel 表中相对应的列名称。
例如,
1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB...
示例 1:
输入: 1 输出: “A”
示例 2:
输入: 28 输出: “AB”
示例 3:
输入: 701 输出: “ZY”
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/excel-sheet-column-title
class Solution {
public String convertToTitle(int n) {
StringBuilder stringBuilder = new StringBuilder();
while (n != 0) {
n--;
stringBuilder.append((char) ('A' + n % 26));
n /= 26;
}
return stringBuilder.reverse().toString();
}
}
