Problem
Given an input string, reverse the string word by word.
For example,
Given s = “
return “
Given s = “
the sky is blue
“,return “
blue is sky the
“.Analysis
- 首先split string by space
- 然后 append word in reverse order
- 注意 如果当前非空,在append下一个word之前,需要append空格
Code
Reference