@@ -0,0 +1,1371 @@
+package algorithm.linkedList;%0A%0A/**%0A * 4. Median of Two Sorted Arrays%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* Example 1:%0A* nums1 = %5B1, 3%5D%0A* nums2 = %5B2%5D%0A* The median is 2.0%0A* Example 2:%0A* nums1 = %5B1, 2%5D%0A* nums2 = %5B3, 4%5D%0A* The median is (2 + 3)/2 = 2.5%0A* Subscribe to see which companies asked this question%0A * https://leetcode.com/problems/median-of-two-sorted-arrays/%0A * @author Allen on 2016/10/12.%0A */%0Apublic class MedianOfTwoSortedArrays %7B%0A%0A    public double findMedianSortedArrays(int%5B%5D nums1, int%5B%5D nums2) %7B%0A        int len1 = nums1.length;%0A        int len2 = nums2.length;%0A%0A        int%5B%5D nums3 = new int%5Blen1 + len2%5D;%0A        int i = 0, i1 = 0, i2 = 0;%0A        while (i1 %3C len1 && i2 %3C len2) %7B%0A            if(nums1%5Bi1%5D %3C nums1%5Bi2%5D) %7B%0A                nums3%5Bi++%5D = nums1%5Bi1++%5D;%0A            %7D else %7B%0A                nums3%5Bi++%5D = nums2%5Bi2++%5D;%0A            %7D%0A        %7D%0A        while (i1 %3C len1) %7B%0A            nums3%5Bi++%5D = nums1%5Bi1++%5D;%0A        %7D%0A        while (i2 %3C len2) %7B%0A            nums3%5Bi++%5D = nums2%5Bi2++%5D;%0A        %7D%0A%0A        int mid = nums3.length / 2;%0A        if(nums3.length %25 2 == 0) %7B%0A            return (double) (nums3%5Bmid - 1%5D + nums3%5Bmid%5D) / 2.0;%0A        %7D else %7B%0A            return (double)nums3%5Bmid%5D;%0A        %7D%0A    %7D%0A%0A%7D%0A

add median of two sorted arrays