LeetCode—557. Reverse Words in a String III


//url:https://leetcode.com/problems/reverse-words-in-a-string-iii/description/
class Solution {
public:
     void SplitString(const string& s, vector& v, const string& c)
    {
        string::size_type pos1, pos2;
        pos2 = s.find(c);
        pos1 = 0;
        while(string::npos != pos2)
        {
            v.push_back(s.substr(pos1, pos2-pos1));

            pos1 = pos2 + c.size();
            pos2 = s.find(c, pos1);
        }
        if(pos1 != s.length())
            v.push_back(s.substr(pos1));
    }
    void reverseString(string& s) {
        int size=s.length();
        for(int i=0;i vec;
        SplitString(s,vec," ");
        string finstr="";
        for(int i=0;i

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注