when I run the testcase nums=[1,2]/k= 1,the result info me that my code is wrong,I think maybe the preset pro is wrong


  • 0
    J

    public void rotate(int[] nums, int k) {
    if (nums == null || nums.length == 0 || nums.length < k)
    return;
    int len = nums.length;
    int tempNums[] = new int[len];
    for (int i = 0; i <len; i++) {
    if (i < k)
    tempNums[i ] = nums[len - k + i];
    if (i >= k)
    tempNums[i ] = nums[i - k];
    }
    nums=tempNums;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.