Length of Last Word
class Solution(object):
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
if len(s) == 0:
return 0
count = 0
for char in reversed(s):
if char !=' ':
count += 1
elif char == ' ' and count != 0:
return count
return countLast updated