class Solution: def lengthOfLastWord(self, s: str) -> int: if len(s) == 0: return 0 s = s[::-1] length = 0 for i,v in enumerate(s): if v == " ": if length > 0: return length else: length += 1 return length