@@ -0,0 +1,1247 @@
+package leetCode;%0A%0A/**%0A * There are two sorted arrays nums1 and nums2 of size m and n respectively.%0A *Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).%0A */%0A%0Apublic class Median %7B%0A    public double findMedianSortedArrays(int%5B%5D nums1,int%5B%5D nums2)%7B%0A        int m = nums1.length,%0A                n = nums2.length;%0A        if(m %3C n)%7B%0A            return findMedianSortedArrays(nums2,nums1);%0A        %7D%0A%0A        if(n == 0)%7B%0A            return (nums1%5B(m - 1) / 2%5D + nums1%5Bm / 2%5D) / 2.0;%0A        %7D%0A%0A        int left = 0,right = 2*n;%0A        while (left %3C= right)%7B%0A            int mid2 = (left + right) / 2;%0A            int mid1 = m + n - mid2;%0A            double L1 = mid1 == 0 ? Double.MIN_VALUE : nums1%5B(mid1 - 1) / 2%5D;%0A            double L2 = mid2 == 0 ? Double.MIN_VALUE : nums2%5B(mid2 - 1) / 2%5D;%0A            double R1 = mid1 == m * 2 ? Double.MAX_VALUE : nums1%5Bmid1 / 2%5D;%0A            double R2 = mid2 == n * 2 ? Double.MAX_VALUE : nums2%5Bmid2 / 2%5D;%0A%0A            if(L1 %3E R2)%7B%0A                left = mid2 + 1;%0A            %7Delse if(L2 %3E R1)%7B%0A                right = mid2 - 1;%0A            %7Delse %7B%0A                return (Math.max(L1,L2) + Math.min(R1,R2))/2;%0A            %7D%0A        %7D%0A        return -1;%0A    %7D%0A%7D%0A

Median of Two Sorted Arrays