My java solution


  • 0
    L
    public int lengthOfLastWord(String s) {
        int length=0;
        s=s.trim();
        for(int i=s.length()-1;i>=0;i--){
            if(s.charAt(i)!=' ') length++;
            else break;
        }
        return length;
    }

Log in to reply
 

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