Reverse words in a string III
September 22, 2022
array-and-hashmapProblem URL: Reverse words in a string III
We will split the words, then reverse each word indivisually, then merge them together and return as result.
class Solution:
def reverseWords(self, s: str) -> str:
return ' '.join(word[::-1] for word in s.split())
Time Complexity: O(n)
Space Complexity: O(1)