Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

004 这里两个有序数组被分割线分割后又合并后的配图有点费解 #112

Closed
hitzhangjie opened this issue Apr 11, 2021 · 1 comment

Comments

@hitzhangjie
Copy link

分割线是为了确保左边所有元素的最大值,小于右边所有元素的最小值,
两个数组的两个分割线将数组分成4份,
这4份合并起来不能构成一个有序数组,文章中将其合并为一个数组的描述方式容易让人误解,
可以强调下合并后的不是有序数组,或者用下面这样的配图,更容易理解点:

image

@halfrost
Copy link
Owner

@hitzhangjie 这道题的真正意图并不是合并 2 个有序数组,切分以后的 4 部分能不能构成有序数组可以不关心。(当然实际情况是这 4 部分一定可以构成有序数组,有 2 个指针分别指向这两个有序数组,每次合并的时候判断这两个指针指的元素大小,据此作为合并的规则)如果这道题按照合并有序数组去做,时间复杂度是 O(m+n),把两者合并成一个有序数组,然后取出中位数即可。但是这样做时间复杂度高了,原因是多做了一些“工作”,此题只要求找到中位数,其他的元素是否有序并不关心。所以我画图的时候故意想弱化具体数值的概念,重点关注在二分切分点左右两个元素的大小关系上。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants