k = 3 the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]
public static void rotate(int[] nums, int k) {
k = k % nums.length;
ArrayList<Integer> list = new ArrayList<Integer>();
int index = nums.length - k;
for (int i = index; i < nums.length; i++) {
list.add(nums[i]);
}
for (int i = 0; i < index; i++) {
list.add(nums[i]);
}
for (int i = 0; i < list.size(); i++) {
nums[i] = list.get(i);
}
}