Length of Last Word

Easy

Topics
String

Given a string s of words and spaces, return the length of the last word. A word is a maximal substring of non-space characters.

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 English letters and spaces, with at least one word.
Run ⌘' · Submit ⌘⏎