189. 轮转数组
小于 1 分钟
189. 轮转数组中等
class Solution {
public void rotate(int[] nums, int k) {
k %= nums.length;
int[] ints = Arrays.copyOfRange(nums, nums.length - k,nums.length);
int[] ints1 = Arrays.copyOfRange(nums, 0, nums.length - k);
for (int i = 0; i < nums.length; i++) {
if(i < ints.length){
nums[i] = ints[i];
}else {
nums[i] = ints1[i - ints.length];
}
}
}
}
Powered by Waline v2.15.5