LeetCode-58-Length of Last Word 水题

来源:互联网 发布:淘宝买家微信付款骗局 编辑:程序博客网 时间:2024/06/05 02:07


class Solution(object):    def lengthOfLastWord(self, s):        """        :type s: str        :rtype: int        """        Len=len(s)        endP=Len-1        flag=-1        while(endP>=0):            if s[endP]!=' ':                flag=endP                break            endP-=1        if flag==-1:return 0        ans=0        for i in range(flag,-1,-1):            if s[i]!=' ':                ans+=1            else:break        return ans


原创粉丝点击