Answers for "Rotate Left k cells"

1

Rotate Left k cells

public static int [] rotateLeft(int [] source, int k){
    int arr[] = copyArray(source, source.length);
    int[] temp = new int[arr.length];
    for (int i=0; i<arr.length; i++) {
        temp[i] = arr[(i + k) % arr.length];
    }
    for (int i=0; i<arr.length; i++) {
        arr[i] = temp[i];
    }

    return arr; 
}
Posted by: Guest on July-03-2021

Browse Popular Code Answers by Language