C++ solution with stringstream


  • 0
    Y
    class Solution {
    public:
        string reverseWords(string s) {
            stringstream ss;
            ss << s;
            string v, n;
            while(ss >> n){
                reverse(n.begin(),n.end());
                v.append(n+' ');
            }
            v.pop_back();
            return v;
        }
    };
    

Log in to reply
 

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