题目描述
如题
思路解析
去除右边空格,分割(“ ”),取最后一个的长度
class Solution:
def lengthOfLastWord(self, s: str) -> int:
if not s or len(s) == 0:
return 0
return len(s.rstrip().split(" ")[-1])

如题
去除右边空格,分割(“ ”),取最后一个的长度
class Solution:
def lengthOfLastWord(self, s: str) -> int:
if not s or len(s) == 0:
return 0
return len(s.rstrip().split(" ")[-1])
本文标题:[LeetCode]58、最后一个单词的长度
本文链接:https://www.haomeiwen.com/subject/obnddctx.html
网友评论