跳至主要內容

189. 轮转数组

T4mako算法贪心数组动态规划小于 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