EZ-understand JAVA solution. 0ms


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

Log in to reply
 

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