标签:根据 test art har || off ++ void 字符串
/* 给定一个字符串(以字符数组的形式给出)和一个偏移量,根据偏移量原地旋转字符串(从左向右旋转) */ public class Lint8 { public static void main(String[] args) { } public void rotateString(char[] str, int offset) { // write your code here if (str == null || str.length == 0)return; offset = offset % str.length; reverse(str, 0, str.length - offset - 1); reverse(str, str.length - offset, str.length - 1); reverse(str, 0, str.length - 1); } private void reverse(char[] str, int start, int end) { for (int i = start, j = end; i < j; i++, j--) { char temp = str[i]; str[i] = str[j]; str[j] = temp; } } }
标签:根据 test art har || off ++ void 字符串
原文地址:https://www.cnblogs.com/cnmoti/p/10817102.html