leetcode 最后一个单词的长度 python
class Solution: def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ l = [] for i in s[::-1].lstrip(): if i != ' ': l.append(i) else: break return len(l) w = Solution() print(w.lengthOfLastWord("hello world")) print(w.lengthOfLastWord("a "))