Reverse Words in a String

Given an input string, reverse the string word by word.

For example, Given s = "the sky is blue", return "blue is sky the".

分析

三步翻转法,先整体翻转,然后每个单词翻转。整体翻转不用trim也不用跳过空格。

split方法

答案

python

split 直接去空格 不需要特殊处理

Last updated

Was this helpful?