My java solution


  • 0
    A
     public int lengthOfLastWord(String s) {
        s= s.trim();
        return s.substring(s.lastIndexOf(' ')+1).length();
    }

Log in to reply
 

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