class Solution {
public:
string ReverseSentence(string str) {
string res = str;
if(str == "")
return res;
int start = 0;
int end = 0;
int cur = 0;
while(cur++ < res.size())
{
if(cur == res.size() || res[cur] == ' ')
{
end = cur - 1;
while(start < end)
swap(res[start++], res[end--]);
start = end = cur + 1;
}
}
start = 0;
end = res.size() - 1;
while(start < end)
swap(res[start++], res[end--]);
return res;
}
};