Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 517 Bytes

58.md

File metadata and controls

34 lines (25 loc) · 517 Bytes

Length of Last String

Description

link


Solution

See Code


Code

O(?)

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