Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9da3575

Browse files
Merge pull request youngyangyang04#2764 from ZaneCodeJourney/0151.python
0151.翻转字符串里的单词 Python 版本1 删除冗余代码
2 parents fa3460c + b328882 commit 9da3575

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,10 @@ class Solution {
440440
```Python
441441
class Solution:
442442
def reverseWords(self, s: str) -> str:
443-
# 删除前后空白
444-
s = s.strip()
445443
# 反转整个字符串
446444
s = s[::-1]
447445
# 将字符串拆分为单词,并反转每个单词
446+
# split()函数能够自动忽略多余的空白字符
448447
s = ' '.join(word[::-1] for word in s.split())
449448
return s
450449

@@ -1029,3 +1028,4 @@ public string ReverseWords(string s) {
10291028
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
10301029
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
10311030
</a>
1031+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /