Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 586 Bytes

168. Excel表列名称.md

File metadata and controls

28 lines (22 loc) · 586 Bytes
  • 进制转换
/**
 *
 * @description 思路跟10进制转2进制一样,类比一下即可
 * @param {number} n
 * @return {*}  {string}
 */
function convertToTitle(n: number): string {
    let result: string = '';

    while (n > 0) {
        const offset: number = (n - 1) % 26;
        result = getUpperCase(offset) + result;
        n = Math.floor((n - 1) / 26);
    }

    return result;
};

function getUpperCase(num: number): string {
    return String.fromCharCode(num + 65);
}