Two line javascript solution


  • 0
    K
    /**
     * @param {string} s
     * @return {number}
     */
    var lengthOfLastWord = function(s) {
        var res = s.trim().split(' ');
        return res.length ? res.pop().length : 0;
    }
    

Log in to reply
 

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