diff --git a/0058-length-of-last-word/0058-length-of-last-word.py b/0058-length-of-last-word/0058-length-of-last-word.py new file mode 100644 index 0000000..be1aecc --- /dev/null +++ b/0058-length-of-last-word/0058-length-of-last-word.py @@ -0,0 +1,6 @@ +class Solution: + def lengthOfLastWord(self, s: str) -> int: + # Split the string by spaces and filter out empty strings + words = [word for word in s.split(" ") if word] + # Return the length of the last word in the filtered list + return len(words[-1]) if words else 0 \ No newline at end of file