58.最后一个单词的长度

class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        count = 0
        local_count = 0
        
        for i in range(len(s)):
            if s[i] == ' ':
                local_count = 0
            else:
                local_count += 1
                count = local_count
        return count

 

posted @ 2019-08-23 21:03  我叫郑小白  阅读(131)  评论(0编辑  收藏  举报