【leetcode❤python】 58. Length of Last Word

#很简单,利用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])

posted @ 2016-10-31 18:42  火金队长  阅读(93)  评论(0编辑  收藏  举报