4.18
public class Solution {
/**
* @param str: an array of char
* @param offset: an integer
* @return: nothing
*/
public void rotateString(char[] str, int offset) {
int count = str.length;
if(count == 0){
return;
}
if(offset == 0){
return;
}
while(offset >= count){
offset = offset % count;
}
char[] tmp = new char[count];
int flag = 0;
for(int i = count - offset;i < count;i++){
tmp[flag ++] = str[i];
}
int k = 0;
while(flag < count){
tmp[flag++] = str[k++];
}
for(int h =0;h<count;h++){
str[h] = tmp[h];
}
// write your code here
}
}

被折叠的 条评论
为什么被折叠?



