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