leetcode——58. 最后一个单词的长度

class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        if s==' '*len(s):
            return 0
        if ' ' not in s:
            return len(s)
        a=s.split(' ')
        i=-1
        while a[i]=='':
            i-=1
        return len(a[i])
执行用时 :44 ms, 在所有 python3 提交中击败了78.73%的用户
内存消耗 :13.6 MB, 在所有 python3 提交中击败了5.01%的用户
 
                                               ——2019.10.16

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11688537.html
今日推荐