class Solution(object):
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
if len(s) == 0:
return 0
temp = s.split(' ')
temp = [t for t in temp if len(t) > 0]
if len(temp) == 0:
return 0
else:
return len(temp[-1])
Download Length of Last Word.pyLeetcode 058 Length of Last Word problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.