Reverse Words in a String# JobHunting - 待字闺中
h*2
1 楼
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 sp
aces.
How about multiple spaces between two words?
Reduce them to a single space in the reversed string.
基本思路就是先整体reverse string (character per character), 之后对于每个word
reverse (character per character),但这题有个要求就是要把多余的spaces去掉,
这个是在per word reverse 里面做呢还是最后再扫一遍呢?
问下大家~~
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 sp
aces.
How about multiple spaces between two words?
Reduce them to a single space in the reversed string.
基本思路就是先整体reverse string (character per character), 之后对于每个word
reverse (character per character),但这题有个要求就是要把多余的spaces去掉,
这个是在per word reverse 里面做呢还是最后再扫一遍呢?
问下大家~~