diff --git a/58-length_of_last_word/python/58.py b/58-length_of_last_word/python/58.py new file mode 100644 index 0000000..deece98 --- /dev/null +++ b/58-length_of_last_word/python/58.py @@ -0,0 +1,10 @@ +# 58. Length of Last Word +# +# Given a string s consisting of words and spaces, return the length of the +# last word in the string. +# +# A word is a maximal substring consisting of non-space characters only. + + +def lengthOfLastWord(s: str) -> int: + return len(s.strip().split(" ")[-1])