给你一个字符串 s,由若干单词组成,单词前后用一些空格字符隔开。返回字符串中 最后一个 单词的长度。

class Solution(object):
    def lengthOfLastWord(self, s):
        """
        :type s: str
        :rtype: int
        """
        b=s.strip()
        a=''.join(b).split(' ')
        c=a[len(a)-1]
        return len(c)

猜你喜欢

转载自blog.csdn.net/Tinyfacture/article/details/131888815