151.翻转字符串里的单词

class Solution:
    def reverseWords(self, s: str) -> str:
        if s == '':
            return s
        
        ls = s.split()
        
        # "   "
        if ls == []:
            return ''
        
        result = ''
        for i in range(0, len(ls)):
            result += ls[-1 - i] + ' '
        # strip()去除首尾空格
        result = result.strip()
        return result

 

posted @ 2019-08-23 21:02  我叫郑小白  阅读(196)  评论(0编辑  收藏  举报