3 lines java solution


  • 0
    U
    public int lengthOfLastWord(String s) {
           s=s.trim();
           if(s.indexOf(" ") ==-1) return s.length();
           return (s.substring(s.lastIndexOf(" "), s.length()-1)).length();
    
    

Log in to reply
 

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