[LeetCode][JavaScript]Excel Sheet Column Title

Excel Sheet Column Title 

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:

    1 -> A
    2 -> B
    3 -> C
    ...
    26 -> Z
    27 -> AA
    28 -> AB

https://leetcode.com/problems/excel-sheet-column-title/






我恨进制转换,傻傻算不清。

/**
 * @param {number} n
 * @return {string}
 */
var convertToTitle = function(n) {
    var res = "";
    var codeA = "A".charCodeAt(); 
    while(n > 0){
        n--;
        res = String.fromCharCode(codeA + n % 26) + res;
        n = parseInt(n / 26);
    } 
    return res;
};


原文地址:https://www.cnblogs.com/Liok3187/p/4507977.html