The length of the last word--Likou

1 question

You are given a string s, which consists of several words separated by some space characters before and after the words. Returns the length of the last word in a string.

A word is the largest substring that consists only of letters and does not contain any space characters.

Example 1:

输入:s = "Hello World"
输出:5

Example 2:

输入:s = "   fly me   to   the moon  "
输出:4

Example 3:

输入:s = "luffy is still joyboy"
输出:6

hint:

1 <= s.length <= 104
s contains only English letters and spaces ' ' and
there is at least one word in s

2 answers

 

Guess you like

Origin blog.csdn.net/weixin_42375493/article/details/121938508