给定一个仅包含大小写字母和空格 ' '
的字符串,返回其最后一个单词的长度。
输入: "Hello World" 输出: 5
class Solution:
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
strlist = s.strip().split(" ")
return len(strlist[-1])
感觉这道题,python的解法真是太快了,用其他语言感觉都基本没这么快