Python solution


  • 1
    H
    def lengthOfLastWord(self, s):
        ans = 0
        for i in xrange(len(s)-1, -1, -1):
            if s[i] != ' ':
                ans += 1
            elif ans:
                break
        return ans

Log in to reply
 

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