Skip to content

Commit

Permalink
Time: 31 ms (80.42%), Space: 16.6 MB (13.88%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-frankliln committed Jul 8, 2024
1 parent 9cdb3e5 commit 228f671
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 0058-length-of-last-word/0058-length-of-last-word.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 228f671

Please sign in to comment.