Created
January 15, 2019 09:34
-
-
Save kanahaiya/0cba02b13035c50e8da56c002f8ff92b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* | |
* @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