mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
update 0151.翻转字符串里的单词 python版本
This commit is contained in:
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user