Skip to content

Instantly share code, notes, and snippets.

@kanahaiya
Created January 15, 2019 09:34
Show Gist options
  • Save kanahaiya/0cba02b13035c50e8da56c002f8ff92b to your computer and use it in GitHub Desktop.
Save kanahaiya/0cba02b13035c50e8da56c002f8ff92b to your computer and use it in GitHub Desktop.
/**
*
* @author Kanahaiya Gupta
*
*/
public class ArraysDS {
// Complete the reverseArray function below.
static int[] reverseArray(int[] a) {
int len = a.length - 1;
for (int i = 0; i <= len / 2; i++) {
swap(a, i, len - i);
}
return a;
}
private static void swap(int[] a, int start, int end) {
int temp = a[start];
a[start] = a[end];
a[end] = temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment