python solution


  • 0
    R
    class Solution(object):
        def lengthOfLastWord(self, s):
            """
            :type s: str
            :rtype: int
            """
            res = 0
            a = s.split(" ")
            for i in range(len(a) - 1,-1,-1):
                if a[i] != "":
                    res = len(a[i])
                    return res
            return res

Log in to reply
 

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