Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
74f15372
Unverified
Commit
74f15372
authored
May 08, 2020
by
Ziyuan Zhang
Committed by
GitHub
May 08, 2020
Browse files
0004_Solved
0004_Solved
parent
bcacf826
Changes
1
Hide whitespace changes
Inline
Side-by-side
0004-median-of-two-sorted-arrays/Article/0004-median-of-two-sorted-arrays.md
View file @
74f15372
...
...
@@ -31,7 +31,7 @@ nums2 = [3, 4]
首先,我们可以只考虑数字总个数为奇数的情况。让我们看下下图:


蓝框是中位数左边的数(包括中位数),而橘框则为中位数右边的数。
...
...
@@ -39,7 +39,7 @@ nums2 = [3, 4]
1.
两个数组的蓝框总个数=(数字总个数+1)/2;
2.
所有蓝框内的数都小于橘框内的数
3.
中位数为蓝框中最大的那一位(即数组1蓝框最后一位,或数组2蓝框最后一位)


如图,我们要找到一组A,B,满足上面3条规则。
对于规则1,我们在数组1中找任意A,然后根据规则1就能推算出对应的B的位置。
对于规则2,由于数组1和2都是有序数组,即X1<A<Y1;X2<B<Y2。我们实际上只需要判断A是否小于Y2,以及B是否小于Y2。
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment