天天看点

[LintCode] Reverse Words in a String 翻转字符串中的单词

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

For example,

Given s = "<code>the sky is blue</code>",

return "<code>blue is sky the</code>".

Have you met this question in a real interview? 

Yes

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.

解法一:

解法二:

解法三:

继续阅读