My javascript answer is wrong,but I test it is correct .Why??


  • 0
    Z

    I test my code in browser is correct ,why not accept?

    var lengthOfLastWord = function(s) {
    var arr=s.split(" ");
    var word=[];
    if(arr.length==0){
        return 0;
    }
    else{
        word=arr[arr.length-1]
        return word.length;
    }
    

    };

    the reason is:

    wrong anwser:
    Input:"a "
    Output:0
    Expected:1


Log in to reply
 

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