package algorithm.lintcode.easy;

public class RotateString {
    public void rotateString(char[] str, int offset) {
        if (str == null || str.length == 0) {
            return;
        }
        offset %= str.length;
        if (offset == 0) {
            return;
        }
        ratateOne(str);
        rotateString(str, offset - 1);
    }

    private void ratateOne(char[] str) {
        char t = str[str.length - 1];
        for (int i = str.length - 1; i > 0; i--) {
            str[i] = str[i - 1];
        }
        str[0] = t;
    }
}

@@ -178,32 +178,65 @@
 turn;%0A        %7D%0A
+        int length = str.length;%0A
         offset %25
@@ -237,20 +237,16 @@
 fset %25= 
-str.
 length;%0A
@@ -315,55 +315,126 @@
    r
-atateOne(str);%0A        rotateString(str, offset
+everse(str, 0, length - offset - 1);%0A        reverse(str, length - offset, length - 1);%0A        reverse(str, 0, length
  - 1
@@ -465,15 +465,13 @@
 id r
-atateOn
+evers
 e(ch
@@ -482,131 +482,172 @@
  str
-) %7B%0A        char t = str%5Bstr.length - 1%5D;%0A        for (int i = str.length - 1; i %3E 0; i--) %7B%0A            str%5Bi%5D = str%5Bi - 1
+, int startIndex, int endIndex) %7B%0A        while (startIndex %3C endIndex) %7B%0A            char startChar = str%5BstartIndex%5D;%0A            str%5BstartIndex++%5D = str%5BendIndex
 %5D;%0A 
@@ -656,30 +656,51 @@
     
- %7D%0A
      
-   
 str%5B
-0%5D = t;
+endIndex--%5D = startChar;%0A        %7D
 %0A   

Refactor rotate string solution