Skip to content

Commit bb213f6

Browse files
committedDec 12, 2020
feat: reverse-words-in-a-string-iii
1 parent bfbc842 commit bb213f6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎str.reverse-words-in-a-string-iii.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
"""
3+
557. 反转字符串中的单词 III
4+
给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。
5+
https://leetcode-cn.com/problems/reverse-words-in-a-string-iii/
6+
"""
7+
def reverseWords(self, s: str) -> str:
8+
arr = s.split(' ')
9+
for i in range(len(arr)):
10+
arr[i] = arr[i][::-1]
11+
return ' '.join(arr)
12+
13+
so = Solution()
14+
print(so.reverseWords('Let\'s take LeetCode contest'))

0 commit comments

Comments
 (0)