-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseWords.py
More file actions
28 lines (28 loc) · 947 Bytes
/
Copy pathreverseWords.py
File metadata and controls
28 lines (28 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution:
def reverseWords(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
tmpStr = ''
tmpLst = []
for i, char in enumerate(s):
if i == len(s) - 1:
tmpStr += char
tmpLst.append(tmpStr)
if char == ' ':
tmpLst.append(tmpStr)
tmpStr = ''
else:
tmpStr += char
tmpLst = tmpLst[::-1]
resultLst = []
for i, v in enumerate(tmpLst):
resultLst += [char for char in v]
resultLst.append(' ')
resultLst.pop()
s = resultLst
# s = "the sky is blue".split()
# s = reversed(s)
# print([word + " " for word in s])
# print([j for j in reversed([1,2,3])])
# # print("".join( [word+" " for word in reversed("the sky is blue".split()) ] ))