给定一个正整数,返回它在 Excel 表中相对应的列名称。
例如,
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
...
示例 1:
输入: 1
输出: "A"
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/excel-sheet-column-title
/**
* @param {number} n
* @return {string}
*/
var convertToTitle = function(n) {
let res = '';
while(n) {
if(n % 26 === 0) {
res += String.fromCharCode(26 + 64);
n = (n/26) - 1;
} else {
res += String.fromCharCode(n % 26 + 64);
n = ~~(n/26); // ~~ 相当于Math.floor()
}
}
return res.split('').reverse().join('');
};