1.简述:
给你一个整数columnumber ,返回它在 Excel 表中对应的列名。
例如:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
示例 1:
输入:columnNumber = 1
输出:"A"
示例 2:
输入:columnNumber = 28
输出:"AB"
示例 3:
输入:columnNumber = 701
输出:"ZY"
示例 4:
输入:columnNumber = 2147483647
输出:"FXSHRXW"
2.实现代码:
class Solution { public String convertToTitle(int columnNumber) { StringBuffer sb = new StringBuffer(); while (columnNumber > 0) { int a0 = (columnNumber - 1) % 26 + 1; sb.append((char)(a0 - 1 + 'A')); columnNumber = (columnNumber - a0) / 26; } return sb.reverse().toString(); }}