Created
November 8, 2015 16:45
-
-
Save ejcer/3c6da959fec9e5f34606 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
public static int[] merge(int[] a, int[] b) { | |
int[] answer = new int[a.length + b.length]; | |
int i = 0, j = 0, k = 0; | |
while (i < a.length && j < b.length) | |
{ | |
if (a[i] < b[j]) | |
answer[k++] = a[i++]; | |
else | |
answer[k++] = b[j++]; | |
} | |
while (i < a.length) | |
answer[k++] = a[i++]; | |
while (j < b.length) | |
answer[k++] = b[j++]; | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment