很好奇还有什么更快的算法
class Solution:
def lengthOfLastWord(self, s: str) -> int:
j = len(s)-1
while j>=0 and s[j]==' ':
j -= 1
i = j
while i>=0 and s[i]!=' ':
i -= 1
return j-i
wx647085015099d ©著作权
很好奇还有什么更快的算法
class Solution:
def lengthOfLastWord(self, s: str) -> int:
j = len(s)-1
while j>=0 and s[j]==' ':
j -= 1
i = j
while i>=0 and s[i]!=' ':
i -= 1
return j-i
限制编辑
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M