2020-05-04 # LeetCode Easy 557. Reverse Words in a String III leetcode tags: leetcode 問題 Explore Problems アイデア 「文字列中にある単語を反転させた文字列を返せ」という問題です. やるだけです. 解法 空白区切りで分解して,分解後の文字列を反転させます. 計算量 文字列の個数を$N$とし,それぞれの単語の最大の長さを$S$とします. 時間計算量 $O(NS)$ 空間計算量 $O(1)$ Python class Solution: def reverseWords(self, s: str) -> str: return " ".join([word[::-1] for word in s.split()])