time limit exceeded how to improve my solution..???


  • 0
    D

    k = k % nums.length;
    int rotated[] = new int[nums.length];
    for (int i = 0; i < nums.length; i++) {
    rotated[i] = nums[i];
    }
    for (int j = 0; j < k; j++) {
    nums[j] = nums[nums.length - (k - j)];
    }
    for (int l = k; l < nums.length ; l++) {
    nums[l] = rotated[l - k];
    }
    for (int m =0; m < nums.length; m++) {
    System.out.print(nums[m]);
    }


Log in to reply
 

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