C++ 5 lines with stringstream


  • 0
    B
    class Solution {
    public:
        void reverseWords(string &s) 
        {
            stringstream ss(s);
            s="";
            string temp;
            while(ss>>temp) s = temp +" "+s;
            if(!s.empty())s.pop_back();
        }
    };

Log in to reply
 

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