Python solution


  • 0
    A

    '''
    class Solution(object):
    def lengthOfLastWord(self, s):
    """
    :type s: str
    :rtype: int
    """
    s = s.strip()
    count = 0
    for i in range(len(s) - 1, -1,-1):
    if s[i] == ' ':
    break
    count += 1

        return count
            
        '''

Log in to reply
 

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