import java.util.*;


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 length1 = arr1.length;
        int length2 = arr2.length;
        int i=0;
        int j=0;
        int[] arr = new int[length1+length2];
        int index = 0;
        //合并数组
        for(;i<length1 && j<length2;){
            if(arr1[i]<arr2[j]){
                arr[index] = arr1[i];
                i++;
            }else{
                arr[index] = arr2[j];
                j++;
            }
            index++;
        }
        
        if(i == length1){//数组1已经合并
            while(j<length2){
                arr[index] = arr2[j];
                j++;
                index++;
            }
        }
        if(j == length2){//数组2已经合并
            while(i<length1){
                arr[index] = arr1[i];
                i++;
                index++;
            }
        }
        
        return arr[(length1+length2-1)/2];//返回上中位数
    }
}