python solution~


  • 0
    U

    class Solution:
    def lengthOfLastWord(self, s):
    """
    :type s: str
    :rtype: int
    """
    a=s.split(' ')
    for x in a[::-1]:
    if x!='' and x!=' ':
    return len(x)
    return 0


Log in to reply
 

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