题解 | #左旋转字符串#
左旋转字符串
http://www.nowcoder.com/practice/12d959b108cb42b1ab72cef4d36af5ec
public:
string LeftRotateString(string str, int n) {
int test;
if(n>str.length()){
if(str.length()==0){
return "";
}
while(n>str.length()){
n-=str.length();
}
test=n;
}
else{
test=n;
}
int i;
string result="";
for(i=n;i<=str.length()-1;i+=1){
result+=str[i];
}
for(i=0;i<=n-1;i+=1){
result+=str[i];
}
cout<<result<<endl;
return result;
}
};