首页 > 其他 > 详细

LeetCode58

时间:2021-02-19 13:27:15      阅读:19      评论:0      收藏:0      [点我收藏+]

LeetCode58:https://leetcode-cn.com/problems/length-of-last-word/

解题思路:利用字符串的内置函数

1 class Solution:
2     def lengthOfLastWord(self, s: str) -> int:
3         return len(s.strip().split( )[-1])

字符串:

strip()方法:移除字符串头尾指定的字符(默认为空格)或字符序列。

split() 通过指定分隔符对字符串进行切片,返回分割后的字符串列表。

 

LeetCode58

原文:https://www.cnblogs.com/vvzhang/p/14415436.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!