Given a string s consisting of words and spaces, return the length of the last word in the string.

A word is a maximal substring consisting of non-space characters only.

&nbsp;
Example 1:

Input: s = "Hello World"
Output: 5
Explanation: The last word is "World" with length 5.


Example 2:

Input: s = "   fly me   to   the moon  "
Output: 4
Explanation: The last word is "moon" with length 4.


Example 3:

Input: s = "luffy is still joyboy"
Output: 6
Explanation: The last word is "joyboy" with length 6.


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 104
	s consists of only English letters and spaces ' '.
	There will be at least one word in s.


class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        return len(s.strip().split()[-1])
class Solution {
    public int lengthOfLastWord(String s) {
        int j=s.length()-1,len=0; boolean flag=true;
        while(j>=0 && (flag || (!flag && s.charAt(j)!=' ')))
            if(s.charAt(j--)!=' '){
                flag=false;
                len++;
            }
        return len;
    }
}
class Solution {
public:
    int lengthOfLastWord(string s) {
        int count = 0;
        int n = s.size();
        int i = n-1;
        while(i>=0){
            if(s[i]==' '){
                i--;
                if(count >0){
                    break;
                }
            }
            else{
                count++;
                i--;
            }
        }
        return count;
    }
};
var lengthOfLastWord = function(s) {
    s = s.split(" ");
    if(s[s.length-1] == ``)
    {
        for(var i = s.length-1; i >= 0; i-- )
        {
            if(s[i].length > 0)
            {
                return s[i].length;
            }
        }
    }
    else
    {
        return s[s.length-1].length;
    }
};
Length of Last Word