Easy to follow java solution


  • 0
    M

    public int lengthOfLastWord(String s) {
    int i=0;
    if(s!=" "){
    String[] arr=s.split(" ");
    if(arr.length>0){
    String last=arr[arr.length-1];
    i=last.length();
    }
    }
    return i;
    }


Log in to reply
 

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