public class Solution {
public void rotate(int[] nums, int k) {
if(nums == null || nums.length < 2){
return;
}
k = k % nums.length;
reverse(nums, 0, nums.length - k - 1);
reverse(nums, nums.length - k, nums.length - 1);
reverse(nums, 0, nums.length - 1);
}
private void reverse(int[] nums, int i, int j){]]
int tmp = 0;
while(i < j){
tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
i++;
j--;
}
}
}
public class Solution {
public void rotate(int[] nums, int k) {
int[] temp = new int[k];
int len = nums.length;
k = k % len;
for(int i = 0; i < k; i++){
temp[i] = nums[len - k + i];
}
for (int i = len - k - 1; i >= 0; i--){
nums[ i + k] = nums[i];
}
for(int j = 0; j < k; j++){
nums[j] = temp[j];
}
}
}