class Solution {
public:
void reverse(string &str,int left,int right){
if(left>=right)
return;
while(left<right){
char tmp=str[left];
str[left]=str[right];
str[right]=tmp;
left++;right--;
}
return;
}
string ReverseSentence(string str) {
if(str=="")
return str;
int left=0,right=0;
while(right<str.length()){
if(str[right]==' '){
reverse(str, left, right-1);
left=right+1;
right++;
}
else{
right++;
}
}
reverse(str, left, right-1);
reverse(str, 0, right-1);
return str;
}
};
public:
void reverse(string &str,int left,int right){
if(left>=right)
return;
while(left<right){
char tmp=str[left];
str[left]=str[right];
str[right]=tmp;
left++;right--;
}
return;
}
string ReverseSentence(string str) {
if(str=="")
return str;
int left=0,right=0;
while(right<str.length()){
if(str[right]==' '){
reverse(str, left, right-1);
left=right+1;
right++;
}
else{
right++;
}
}
reverse(str, left, right-1);
reverse(str, 0, right-1);
return str;
}
};