# 168. Excel Sheet Column Title

主要考 recursion 很不熟練應該要在練一下

LeetCode

/**
 * @param {number} n
 * @return {string}
 */

var convertToTitle = function(n) {
  var dict =['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' ];
    var result = '';
    if( n<=26 ){
        return dict[n-1];
    }
    while( n ){
        var val = (n-1)%26;
        result = dict[val] + result;
        n = Math.floor( (n-1) /26 );
    }
    return result;    
};

Last updated