Skip to content

Instantly share code, notes, and snippets.

@ejcer
Created November 8, 2015 16:45
Show Gist options
  • Save ejcer/3c6da959fec9e5f34606 to your computer and use it in GitHub Desktop.
Save ejcer/3c6da959fec9e5f34606 to your computer and use it in GitHub Desktop.
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