归并排序
public class Solution {
/**
* find median in two sorted array
* @param arr1 int整型一维数组 the array1
* @param arr2 int整型一维数组 the array2
* @return int整型
*/
public int findMedianinTwoSortedAray (int[] arr1, int[] arr2) {
// write code here
int n = arr1.length;
int[] res = new int[2*n];
int left = 0;
int right = 0;
int k = 0;
while (left<n&&right<n){
if (arr1[left]<=arr2[right]){
res[k++] = arr1[left++];
}else {
res[k++] = arr2[right++];
}
}
while (left<n){
res[k++] = arr1[left++];
}
while (right<n){
res[k++] = arr2[right++];
}
return res[n-1];
}
}