My 32 ms Python solution


  • 0
    D

    class Solution(object):
    def lengthOfLastWord(self, s):

        sum = 0
        c = 0
    
        for i in range(len(s)-1,-1,-1):
                
            if s[i]!=' ':
                sum +=1
                c +=1
            if s[i]==' 'and c>=1:
                break
                        
        return (sum)

Log in to reply
 

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