Javascript beat 100% 152ms


  • 3
    Y

    /**

    • @param {string} s
    • @return {number}
      */

    var titleToNumber = function(s) {

        var result = 0;
        
        var sLength = s.length;
        
        for (var i = 0; i < sLength; i++)
        {
             result = result * 26 + (s.charCodeAt(i) - 'A'.charCodeAt(0) + 1);
        }
        
        return result;
    

    };


  • 0
    H

    'A'.charCodeAt(0) is a constant and you could at least save that time.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.