Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters “ ”, return the length of last word in the string. If the last word does not exist, return 0.
(字符串最后一个单词的长度)
Note:
A word is defined as a character sequence consists of non-space characters only.
Example:
1. 字符串处理
本题考查python
中基本的字符串处理函数,比较简单。具体实现方法如下:
(其中之所以需要使用 strip()
是因为当字符串为 “a ” 时,最后一个单词应该是 “a”)
1 | class Solution: |