Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

rotate array

public static int[] Rotate(int[] arr , int k)
{
    k %= arr.Length;

    var ls = new int[arr.Length];

    for (int i = 0; i < ls.Length-k; i++)
    {
        ls[i+k] = arr[i];
    }
    var j = ls.Length-k;
    for (int i = 0; i < k; i++)
    {
        ls[i] = arr[j++];
    }

    return ls;
}
 
PREVIOUS NEXT
Tagged: #rotate #array
ADD COMMENT
Topic
Name
6+9 =