# LeetCode 4：Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively.

Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

Example 1:

```nums1 = [1, 3]
nums2 = [2]

The median is 2.0
```

Example 2:

```nums1 = [1, 2]
nums2 = [3, 4]

The median is (2 + 3)/2 = 2.5
```

`package com.maoxiaomeng;import java.util.ArrayList;import java.util.Collections;import java.util.List;/** * @author lihui * @date 2018/3/25 15:23 */public class Solution {    public double findMedianSortedArrays(int[] nums1, int[] nums2) {        List<Integer> myList = new ArrayList<Integer>();        for (int num : nums1) {            myList.add(num);        }        for (int num: nums2) {            myList.add(num);        }        Collections.sort(myList);                int len1 = nums1.length;        int len2 = nums2.length;        int len = len1 + len2;        double temp = 0.0;        if (len % 2 == 0) {            temp = (myList.get(len / 2) + myList.get(len / 2 - 1)) / 2.0;        } else {            temp = myList.get((len - 1) / 2);        }                return temp;    }}`