Skip to content

Commit 20db66e

Browse files
committed
update 0151.翻转字符串里的单词 python版本
1 parent 8452d5f commit 20db66e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

problems/0151.翻转字符串里的单词.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,13 @@ class Solution:
467467
# 将列表转换成字符串
468468
return " ".join(words)
469469
```
470+
(版本三) 拆分字符串 + 反转列表
471+
```python
472+
class Solution:
473+
def reverseWords(self, s):
474+
words = s.split() #type(words) --- list
475+
words = words[::-1] # 反转单词
476+
return ' '.join(words) #列表转换成字符串
470477

471478
### Go:
472479

0 commit comments

Comments
 (0)