Created
December 18, 2018 20:42
-
-
Save randyhbh/9e238ff9abc72694cfb342d3267bde9d to your computer and use it in GitHub Desktop.
A left rotation operation on an array shifts each of the array's elements 1 unit to the left.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int[] rotLeft(int[] a, int d) { | |
int [] rotated = new int[a.length]; | |
for (int i = 0; i <= a.length - 1; i++) { | |
rotated[i] = a[(i + d) % a.length]; | |
} | |
return rotated; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment