Intuition
- Have to join via a ’ ’ at the end
Complexity
Runtime
Space
Code
class Solution:
def reverseWords(self, s: str) -> str:
split = s.split()
res = []
for word in split:
res.append(word[::-1])
return ' '.join(res)Using Reversed
class Solution:
def reverseWords(self, s: str) -> str:
split = s.split()
res = []
for word in split:
res.append(''.join(list(reversed(word))))
return ' '.join(res)Notes
References
https://leetcode.com/problems/reverse-words-in-a-string-iii/description/