#-*- 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 ')
相关文章
- 10-11[leetcode]Word Ladder II @ Python
- 10-11[LeetCode&Python] Problem 720. Longest Word in Dictionary
- 10-11【Length of Last Word】cpp
- 10-11LeetCode58_Length of Last Word
- 10-11【leetcode】Word Break(python)
- 10-11每天一道LeetCode--58. Length of Last Word
- 10-11[LeetCode]题解(python):139-Word Break
- 10-11LeetCode 58. Length of Last Word【模拟/字符串】简单
- 10-11LeetCode OJ:Length of Last Word
- 10-11[LeetCode]题解(python):127-Word Ladder