1
class Solution:
2
def reverseWords(self, s: str) -> str:
3
s = s + " "
4
l = len(s)
5
t = ""
6
w = ""
7
for i in range(l):
8
if s[i] != " ":
9
t = s[i] + t # t stores the word in reverse order
10
else:
11
# w stores the reversed word in the same order
12
w = (
13
w + t + " "
14
) # could have used .join() function and not write .strip()
15
t = "" # value of t is null so that it won't affect upcoming words
16
return w.strip() # removes extra whitespace

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0