> For the complete documentation index, see [llms.txt](https://r24zeng.gitbook.io/leetcode-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r24zeng.gitbook.io/leetcode-notebook/wan-quan-an-zhao-jiu-zhang-suan-fa-shua-de-60-dao-zuo-you/ii.-sorted-array/4.-median-of-two-sorted-arrays.md).

# 4. Median of Two Sorted Arrays

\# Hard

### Solution 1:

Compare the `len(nums1)/2`th  and `len(nums2)/2`th element, increase or decrease the position based on different situations. Very hard. Give up temporary. Time complexity is $$O(lg(min(m,n)))$$&#x20;

[Detail explanation tutorial](https://medium.com/@hazemu/finding-the-median-of-2-sorted-arrays-in-logarithmic-time-1d3f2ecbeb46)

### Solution 2:

Think about it as finding the `k`th element in two sorted array. Compare the`k/2`th element in `nums1` and `k/2`th element in `nums2`, then throw `k/2` element. This algorithm uses iteration with binary search. Its time complexity is $$O(lgk)$$&#x20;

![](https://3288217904-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LxJcc9A1TOyn5a5HJQ4%2F-M70SrlytwnOPWRuSMl3%2F-M70acIW4js72OMMtlz1%2F1589164781291.jpg?alt=media\&token=c2575f85-c0c4-4407-844d-b7ce88b438d7)
