class Solution { public: /** * @param s : A string * @return : A string */ string reverseWords(string s) { string res = "", t = ""; istringstream is(s); while (getline(is, t, ' ')) { if (t.empty()) continue; res = (res.empty() ? t : (t + " " + res)); } return res; } };
http://www.cnblogs.com/grandyang/p/6065544.html
LeetCode上相同问题的解法如下:
http://www.cnblogs.com/grandyang/p/6065544.html
需要注意的几点:
1.c++中,“a”表示字符串,‘a’表示字符
2.void没有返回值,其余函数都要有return