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
原文地址:https://www.cnblogs.com/WJZheng/p/11402617.html
时间: 2024-10-07 15:39:41