Reverse Words in a String III
String Simulation
Problem
Thought Process
Solution
class Solution:
def reverseWords(self, s: str) -> str:
s = list(s)
j = 0
i = 0
while i < len(s):
while i < len(s) and s[i] != ' ':
i+=1
s[j:i] = s[j:i][::-1]
i+=1
j = i
return("".join(s))Time Complexity
Last updated