旋转字符串 public class Solution { /** * @param str: An array of char * @param offset: An integer * @return: nothing */ public void rotateString(char[] str, int offset) { // write your code here if(offset == 0 || str.length == 0){ return; } offset = offset % str.length; char[] temp = new char[offset]; for(int i = 0; i < offset; i++){ temp[i] = str[str.length - offset + i]; } for(int i = str.length - offset - 1; i >= 0; i--){ str[i + offset] = str[i]; } for(int i = 0; i < offset; i++){ str[i] = temp[i]; } } } 复制代码 转载于:https://juejin.im/post/5b023d85518825428630c977