Skip to content

Latest commit

 

History

History

length-of-last-word

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

58. Length of Last Word

Easy


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:

Input: s = "Hello World"
Output: 5

Example 2:

Input: s = " "
Output: 0

 

Constraints:

  • 1 <= s.length <= 104
  • s consists of only English letters and spaces ' '.