C++ solution: istringstream help to seperate string


  • 0
    G
        string reverseWords(string s) {
            istringstream iss(s);
            string work_str;
            string result("");
            while(getline(iss,work_str,' ')) {
                reverse(work_str.begin(),work_str.end());
                result += work_str;
                result += " ";
            }
            result = result.substr(0,result.size()-1);
            return result;
        }
    

Log in to reply
 

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