C++ Simple and Easy, beats 97% cpp submissions


  • 0
    R
    class Solution {
    public:
        void reverseWords(string &s) {
            stack<string> result_;
            string x,result;
            istringstream str(s);
            while (str >> x)
            {
                result_.push(x);
            }
            while(!result_.empty())
            {
                result += (result_.top());
                result_.pop();
                if(!result_.empty()) result += ' ';
            }
        s = result;    
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.