Python学习——leetcode(Length of Last Word)

来源:互联网 发布:为什么俞飞鸿抗老 知乎 编辑:程序博客网 时间:2024/06/06 15:46
class Solution:    # @param s, a string    # @return an integer    def lengthOfLastWord(self, s):words=s.strip()#去掉前后空格if words:if words.count(' ')==0:#统计内部空格return len(words)else:word=words.split()#根据空白拆分return len(word[len(word)-1])else:return 0

0 0