Length of Last Word

Problem Given a string consisting of words and spaces, return the length of the last word. A word is a maximal substring of non-space characters; there may be trailing spaces.

Input / Output

  • Input: string s containing words separated by spaces.
  • Output: the length of the last word (integer).

Constraints

  • 1 ≤ |s| ≤ 10^4.
  • s consists of English letters and spaces; there is at least one word.

Example

  • "Hello World" -> 5
  • " fly me to the moon " -> 4
  • "luffy is still joyboy" -> 6
added …
LeaderboardSalaryAccount