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.
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.
Constraints:
- 1 <= s.length <= 104
- s consists of only English letters and spaces โ โ.
- There will be at least one word in s.