class Solution {
public:
//翻转一个string字符串
void reverse(string& str,int left,int right){
if(str=="")
return;
while(left<right){
char tmp=str[left];
str[left]=str[right];
str[right]=tmp;
left++;
right--;
}
return;
}
string LeftRotateString(string str, int n) {
if(str=="")
return str;
n=n%str.length();
if(n==0)
return str;
reverse(str, 0, n-1);
reverse(str, n, str.length()-1);
reverse(str, 0, str.length()-1);
return str;
}
};
public:
//翻转一个string字符串
void reverse(string& str,int left,int right){
if(str=="")
return;
while(left<right){
char tmp=str[left];
str[left]=str[right];
str[right]=tmp;
left++;
right--;
}
return;
}
string LeftRotateString(string str, int n) {
if(str=="")
return str;
n=n%str.length();
if(n==0)
return str;
reverse(str, 0, n-1);
reverse(str, n, str.length()-1);
reverse(str, 0, str.length()-1);
return str;
}
};