Python's version of solution


  • 0
    class Solution:
        def lengthOfLastWord(self, s):
            """
            :type s: str
            :rtype: int
            """
            
            self.s = s
            
            word_list = s.strip().split(" ")
            
            if len(word_list) == 0 :
                return 0
            else:
                return len(word_list[-1])
    

Log in to reply
 

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