We’re preparing your current view and syncing the latest data.
Given a string s consisting of words and spaces, return the length of the last word in the string. A word is defined as a maximal substring consisting of non-space characters only. If there is no last word, return 0.
A single string s.
An integer representing the length of the last word in the input string.
1 <= s.length <= 10^4 s consists of only English letters and spaces ' '.
Example 1
Input
"Hello World"
Output
5
Explanation
The last word is "World" which has length 5.
Example 2
Input
" fly me to the moon "
Output
4
Explanation
The last word is "moon" with length 4.
Example 3
Input
"luffy is still joyboy"
Output
6
Explanation
The last word is "joyboy" of length 6.