题目:
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
解题思路:
1、先对字符串进行一次总的翻转
2、以空格为单位,划分单词,然后对每个单词再进行一次翻转
代码:
class Solution { public: void swap(char& a, char& b){ int tmp = a; a = b; b = tmp; } void reverse(string &s, int begin, int end){ if (s[begin] == '