Basic Java Solution


  • 0
    L
    public int lengthOfLastWord(String s) {
           int i,count=0;
           for(i=s.length()-1; i>=0 && !Character.isLetter(s.charAt(i));i--);
           while(i>=0 && Character.isLetter(s.charAt(i))) {
               count++;
               i--;
           }       
           return count;
        }
    

Log in to reply
 

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