```
public void rotate(int[] nums, int k) {
if (k >nums.length){
k = k%nums.length;
}
int end = nums.length;
nums = reverse(nums,0,end-k-1);
nums = reverse(nums,end-k,end-1);
nums = reverse(nums,0,end-1);
}
private int[] reverse(int[] nums, int start, int end){
while(start<end){
int temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
start++; end--;
}
return nums;
}
```