[Leet Code] Length of Last Word

Input: s = "Hello World"
Output: 5
Explanation: The last word is "World" with length 5.
Input: s = "   fly me   to   the moon  "
Output: 4
Explanation: The last word is "moon" with length 4.
Input: s = "luffy is still joyboy"
Output: 6
Explanation: The last word is "joyboy" with length 6.
class Solution(object):
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
answers = []
for i in s.split(" "):
answers.append(i)
answers.reverse()
for i in answers:
if i != "":
return len(i)

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

Easy and readable React/GraphQL/Node Stack — Part 4

WebGoat SSRF 2 3

4 More JavaScript Concepts That Every Developer Should Know

Blog for my Fianceé, Part 1: Boilerplate and Design

Deep Linking Your React Native App Reloaded

uxFirst

How We Paid Firebase, The Money We Never Made

React & Laravel Application

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

[Leet Code] Maximum Number of Words Found in Sentences

Last Stone Weight💧

125. Valid Palindrome in Python3

All Possible Full Binary Trees Solution | LeetCode-894: Medium | JavaScript Implementation