Skip to content

Instantly share code, notes, and snippets.

@randyhbh
Created December 18, 2018 20:42
Show Gist options
  • Save randyhbh/9e238ff9abc72694cfb342d3267bde9d to your computer and use it in GitHub Desktop.
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.
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