Length of Last Word
EasyP3Coding
s consists of words separated by spaces, and may have leading, trailing or repeated spaces. A word is a maximal run of non-space characters. Return the length of the last word. s contains at least one word.
Example 1
- Input
- s = "Hello World"
- Output
- 5
Example 2
- Input
- s = " fly me to the moon "
- Output
- 4
Example 3
- Input
- s = "luffy is still joyboy"
- Output
- 6
Constraints
- 1 <= s.length <= 10^4
- s consists of letters and spaces.
- s contains at least one word.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.