58. Length of Last Word
Input: "Hello World"
Output: 5class Solution(object):
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
container = []
flush = 0
for i in range(len(s)):
if s[i] == ' ':
flush = 1
else:
if flush == 1:
container = []
flush = 0
container.append(s[i])
return len(container)Last updated