版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ShellDawn/article/details/88910411
有坑,注意空串的特殊样例。
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
string LeftRotateString(string str, int n) {
int l = str.length();
n = n%l;
string ans;
for(int i=0;i<l-n;i++){
ans += str[n+i];
}
for(int i=l-n;i<l;i++){
ans += str[i-l+n];
}
return ans;
}
};
int main(){
Solution S;
cout<<S.LeftRotateString("a",3)<<endl;
return 0;
}