why my code is not accepted?


  • 0

    public void rotate(int[] nums, int k)
    {
    int n = nums.length;
    int[] res = new int[n];
    if(k > n)
    {
    k = k-n;
    }
    for(int i =0;i<n;i++)
    {
    if(i+k < n)
    {
    res[i+k] = nums[i];
    }
    else
    {
    res[i+k-n] = nums[i];
    }
    }
    System.out.println(Arrays.toString(res));
    }


Log in to reply
 

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