Solution 1 - Split, Reverse, Join
Reverse each word individually.
""" 0557.1 - Reverse Words in a String III - Solution 1 - Split, Reverse, Join """
class Solution:
def reverseWords(self, s: str) -> str:
return " ".join(word[::-1] for word in s.split(" "))
if __name__ == "__main__":
print(Solution().reverseWords("Let's take LeetCode contest"))Solution 2 - Two Pointers on Char Array
Reverse each word in-place within a mutable char array.