Share my solution in c++


  • 0
    Y
    void reverseWords(string &s) {
                 vector<string> str;
    		stringstream strs(s);
    		string word;
        while(strs>>word)
        str.push_back(word);
    
    	for(int i = str.size() - 2; i>=0; i--)
    	{
    		word.append(" ");
    		word.append(str[i]);
    	}
       s = word;
        }

Log in to reply
 

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