class Solution { public: string ReverseSentence(string str) { string temp,res; for(int i=str.size()-1;i>-1;i--){ if(str[i]!=' ') temp.push_back(str[i]); else{ reverse(temp.begin(),temp.end()); res+=temp+" "; temp.clear(); } } reverse(temp.begin(),temp.end()); res+=temp; return res; } };