From 211fcd1dfa51de068a1f869ed4061907d992e4fa Mon Sep 17 00:00:00 2001 From: sangge <2251250136@qq.com> Date: Sat, 9 Mar 2024 04:24:15 +0800 Subject: [PATCH] finish 58 --- leetcode/58.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 leetcode/58.py diff --git a/leetcode/58.py b/leetcode/58.py new file mode 100644 index 0000000..2b3edb1 --- /dev/null +++ b/leetcode/58.py @@ -0,0 +1,11 @@ +""" +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. +""" +class Solution: + def lengthOfLastWord(self, s: str) -> int: + s = s.strip() + s = s.split(" ") + return len(s[-1])