Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 570 Bytes

数组 矩阵.md

File metadata and controls

21 lines (14 loc) · 570 Bytes

189. 旋转数组


    public void rotate(int[] nums, int k) {


        k = k % nums.length;
        int[] numResult = new int[nums.length];
        for (int j = 0; j < nums.length; j++) {
            numResult[j] = nums[(j + nums.length - k) % nums.length];
        }
        for (int i = 0; i < nums.length; i++) {
            nums[i] = numResult[i];
        }
    }