Skip to content

Instantly share code, notes, and snippets.

@sadv1r
Created July 24, 2014 09:22
Show Gist options
  • Save sadv1r/315a742a41f9f9966180 to your computer and use it in GitHub Desktop.
Save sadv1r/315a742a41f9f9966180 to your computer and use it in GitHub Desktop.
package ru.sadv1r.study.core.array;
/**
* Created by IntelliJ IDEA.
* User: Sadv1r
* Date: 7/24/14
* Time: 10:06
*/
public class Merger {
public static int[] merge(int[] first, int[] second) {
int[] result = new int[first.length + second.length];
int firstIndex = 0;
int secondIndex = 0;
while (firstIndex + secondIndex != result.length) {
if (first[firstIndex] < second[secondIndex]) {
result[firstIndex + secondIndex] = first[firstIndex++];
} else {
result[firstIndex + secondIndex] = second[secondIndex++];
}
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment