My simple javascript solution


  • 0
    K
    var lengthOfLastWord = function(s) {
    if(!s)return 0;
    s=s.trim();
    if(s.localeCompare("")==0)return 0;
    var str=s.split(" ");
    var size=str.length-1;
    return str[size].length;
    

    };


Log in to reply
 

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