C++ Solution With istringstream


  • 2
    H
    string reverseWords(string s) {
    	istringstream iss{s};
    	auto iter = s.begin();
    	for (string word; iss >> word;) {
    		iter = copy(word.rbegin(), word.rend(), iter);
    		if (iter != s.end())
    			++iter;
    	}
    	return s;
    }
    

Log in to reply
 

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