64ms python solution


  • 1
    class Solution(object):
        def lengthOfLastWord(self, s):
            if s == "":
                return 0
                
            curLength = 0
            lastWordLength = 0
            for ch in s:
                if ch == " ":
                    curLength = 0
                    continue
                curLength += 1
                lastWordLength = curLength
            return lastWordLength

Log in to reply
 

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