Introduction
1.Description(Easy)
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
Clarification
What constitutes a word? A sequence of non-space characters constitutes a word.
Could the input string contain leading or trailing spaces? Yes. However, your reversed string should not contain leading or trailing spaces.
How about multiple spaces between two words? Reduce them to a single space in the reversed string.
2.Code
用split函数将string分成一个一个单词,在从后往前一次append到stringbuilder中,注意最后检查下是否remove last space,但是test中不加这个检查也能pass。
Last updated