#-*- coding: UTF-8 -*-
#利用strip函数去掉字符串去除空格(其实是去除两边【左边和右边】空格)
#利用split分离字符串成列表
class Solution(object):
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
if s==None:return 0
slist=s.strip().split(' ')
return len(slist[-1])
sol=Solution()
print sol.lengthOfLastWord('hello ')
相关文章
- 【LeetCode】819. Most Common Word 解题报告(Python)
- 【LeetCode】140. Word Break II 解题报告(Python & C++)
- 【leetcode❤python】 58. Length of Last Word
- [leetcode]58. Length of Last Word最后一个词的长度
- LeetCode——Length of Last Word
- [LeetCode&Python] Problem 748. Shortest Completing Word
- 【leetcode❤python】 290. Word Pattern
- 【leetcode】length of last word (easy)
- [leetcode]Word Break II @ Python
- 【LeetCode】139. Word Break 解题报告(Python & C++)