容易_53_翻转字符串(2)

来源:互联网 发布:软件项目验收表 编辑:程序博客网 时间:2024/05/04 09:09

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