update 0151.翻转字符串里的单词 python版本

This commit is contained in:
Henry Zheng
2024-03-29 11:11:39 +08:00
parent 8452d5f067
commit 20db66e8fb

View File

@ -467,6 +467,13 @@ class Solution:
# 将列表转换成字符串
return " ".join(words)
```
(版本三) 拆分字符串 + 反转列表
```python
class Solution:
def reverseWords(self, s):
words = s.split() #type(words) --- list
words = words[::-1] # 反转单词
return ' '.join(words) #列表转换成字符串
### Go