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
0a528f26
Unverified
Commit
0a528f26
authored
May 08, 2020
by
Ziyuan Zhang
Committed by
GitHub
May 08, 2020
Browse files
0004_Solved
0004_Solved
parent
1d540ec3
Changes
1
Show whitespace changes
Inline
Side-by-side
0004-median-of-two-sorted-arrays/Article/0004-median-of-two-sorted-arrays.md
View file @
0a528f26
...
...
@@ -51,6 +51,7 @@ nums2 = [3, 4]
**情况1:**

首先,我们选择数组1进行操作。取其中间值9 。(因此 A=9) 根据规则1,我们在数组2中找到对应值(B = 4)。(一共有11个数,(11+1) / 2 = 6,因此蓝色框总数为6)
紧接着,我们根据规则2判断A(9)是否小于B.next(5),以及B(4)是否小于A.next(11)。
显然,A比B.next,也就是一个橘框还要大。这是不允许的。可见A只能取比9更小的数字了。如果取更大的数字,那B就会更小,更不可能满足规则2。所以这种情况下我们要向左进行二分。
...
...
@@ -58,11 +59,13 @@ nums2 = [3, 4]
**情况2:**

这种情况下B比A.next,也就是一个橘框还要大。这是不允许的。可见A只能取比9更大的数字了。如果取更小的数字,那B就会更大,更不可能满足规则2。所以这种情况下我们要向右进行二分。
**情况3:**

随着我们不断地二分,中位数显然必然会出现。
如图上这种情况,A小于B.next,且B小于A.next。
那么,显然,A,B中较大的那一项就是中位数(规则3)。
...
...
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