58. Length of Last Word
π© Easy
Question
Input: "Hello World"
Output: 5Code
def lengthOfLastWord(self, s: str) -> int:
# strip() removes leading and trailing character
# default: whitespace
s = s.strip().split(" ")
return len(s[-1])Last updated