[Rotate Array] Different outputs from LeetCode comparing to my own IDLE

  • 0

    Here is my code:

    public class Solution {
        public void Rotate(int[] nums, int k) {
            int length = nums.Length;
            k = k % length;
            int[] sub = new int[k];
            int[] sub2 = new int[length - k];
            Array.Copy(nums, length-k, sub, 0, k);
            Array.Copy(nums, 0, sub2, 0, length-k);
            int[] result = new int[length];
            sub.CopyTo(result, 0);
            sub2.CopyTo(result, k);

    Output from LeetCode:

    Input: [1,2], 1

    Output: [1,2]

    Expected: [2,1]

    However, when I run the same code my own IDLE, it did give me the result value [2,1] which is correct.

    Anyone can help me to look at it? Thank you very much!

Log in to reply

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