Using Stack and stringstream for O(N) solution


#1
string Solution::solve(string A) {
        stringstream ss(A);
        stack<string> st;
        string word;
        while(ss>>word)
        {
            st.push(word);
        }
        string op;
        while(st.size())
        {
            string s2=st.top();
            st.pop();
            op+=s2;
            op+=" ";
        }
        op.pop_back();
        return op;

    }