You are viewing a single comment's thread. Return to all comments →
static int[] leftRotation(int[] a, int d) { for (int i = 0, j = a.length - 1; i < j; i++, j--) swap(a, i, j); d %= a.length; if (d > 0) { d = a.length - d; for (int i = 0, j = d - 1; i < j; i++, j--) swap(a, i, j); for (int i = d, j = a.length - 1; i < j; i++, j--) swap(a, i, j); } return a; } private static void swap(int[] arr, int i, int j) { int tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; }
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →