题解 | #Excel列名称#
https://www.nowcoder.com/practice/bb1e84f98b1640efbf2c6d3fc122bd04
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @return string字符串
*/
function ExcelTitle( n ) {
const s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const map = new Map();
for (let i = 0; i < s.length; i++) {
map.set(i+1, s[i]);
}
let res = '';
while(n) {
let d = n % 26;
if (d=== 0) {
res = 'Z' + res;
n = n - 26;
}
else {
res = (map.get(d) || '') + res;
}
n = Math.trunc(n/26);
}
return res;
// write code here
}
module.exports = {
ExcelTitle : ExcelTitle
};
