@@ -0,0 +1,979 @@
+package leetcode.rotate_array;%0A%0Apublic class Solution %7B%0A    int gcd(int a, int b)%7B%0A        while(b != 0)%7B%0A            int tmp = a;%0A            a = b;%0A            b = tmp %25 b;%0A        %7D%0A        return a;%0A    %7D%0A    public void rotate(int%5B%5D nums, int k) %7B%0A        if(nums == null %7C%7C nums.length == 0) return;%0A        int length = nums.length;%0A        k = (k %25 length + length) %25 length;%0A        int g = gcd(length, k);%0A        for(int i = 0; i %3C g; i++)%7B%0A            int tmp = nums%5Bi%5D;%0A            int cur = i;%0A            for(int j = 0; j %3C length / g - 1; j++)%7B%0A                nums%5Bcur%5D = nums%5B(cur - k + length) %25 length%5D;%0A                cur = (cur - k + length) %25 length;%0A            %7D%0A            nums%5Bcur%5D = tmp;%0A        %7D%0A    %7D%0A    %0A    public static void main(String%5B%5D args)%7B%0A        int%5B%5D ary = new int%5B%5D%7B1, 2, 3, 4%7D;%0A        new Solution().rotate(ary, 4);%0A        for(int x : ary)%7B%0A            System.err.print(x + %22 %22);%0A        %7D%0A        System.err.println(%22%22);%0A    %7D%0A%7D

Add java solution for 189. Rotate Array