python two while loop


  • 0
    Y
    class Solution(object):
        def lengthOfLastWord(self, s):
            """
            :type s: str
            :rtype: int
            """
            if len(s)==0:
                return 0
            i=len(s)-1
            n=0
            m=0
            while s[i]==' ' and i>0:
                i=i-1
                m=m+1
            while n<len(s)-m and s[i]!=' ':
                i=i-1
                n=n+1
            return n
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.