leetcode -- Length of Last Word -- 太简单

https://leetcode.com/problems/length-of-last-word/

class Solution(object):
    def lengthOfLastWord(self, s):
        """ :type s: str :rtype: int """
        if not s:
            return 0
        #if s[-1] == " ":
           # return 0
        list1 = s.split()
        if len(list1) > 0:
            return len(list1[-1])
        else:
            return 0

你可能感兴趣的:(LeetCode)