Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a528f2

Browse files
authored
0004_Solved
0004_Solved
1 parent1d540ec commit0a528f2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

‎0004-median-of-two-sorted-arrays/Article/0004-median-of-two-sorted-arrays.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@ nums2 = [3, 4]
5151
**情况1:**
5252

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

5859
**情况2:**
5960

6061
![](../Animation/case2.png)
62+
6163
这种情况下B比A.next,也就是一个橘框还要大。这是不允许的。可见A只能取比9更大的数字了。如果取更小的数字,那B就会更大,更不可能满足规则2。所以这种情况下我们要向右进行二分。
6264

6365
**情况3:**
6466

6567
![](../Animation/case3.png)
68+
6669
随着我们不断地二分,中位数显然必然会出现。
6770
如图上这种情况,A小于B.next,且B小于A.next。
6871
那么,显然,A,B中较大的那一项就是中位数(规则3)。

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp