Length of Last Word
Given a string s
consists of some words separated by spaces, return the length of the last word in the string. If the last word does not exist, return 0
.
A word is a maximal substring consisting of non-space characters only.
Example 1:
Example 2:
Constraints:
1 <= s.length <= 104
s
consists of only English letters and spaces' '
.
Solutions
🐍 Python
🧠 Cpp
Last updated
Was this helpful?