Simple solution using String stream in c++


#1

Blockquote
string Solution::solve(string s) {
vectorstr(s.length());
stringstream test(s);
string tmp;

    while(test >> tmp){
        str.push_back(tmp);
    }
    
    
    reverse(str.begin(), str.end());
    
     string ans;
    for(string st : str)
        if(st.size())
            ans+=st + " ";
        
    ans.pop_back();
    return ans;

}

Blockquote