Problems

8. Length of Last Word

EasyStringAmazonMicrosoft

Given a string s, return the length of its last word.

Example 1:

Input: s = "Hello World"
Output: 5

Example 2:

Input: s = "   fly me   to   the moon  "
Output: 4

Constraints:

  • 1 <= s.length <= 10^4
Core code mode
● Auto-savedLine 1, column 1