Arrays: Left Rotation

  • + 3 comments

    Here's my in-place function implementation:

    public static int[] arrayLeftRotation(int[] a, int n, int k) {
        // Rotate in-place
        int[] temp = new int[k];
        System.arraycopy(a, 0, temp, 0, k);
        System.arraycopy(a, k, a, 0, n - k);
        System.arraycopy(temp, 0, a, n - k, k);
        return a;
    }