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

0004 合并nums1, nums2时间复杂度不应该是O(m+n)? #111

Closed
hitzhangjie opened this issue Apr 11, 2021 · 3 comments
Closed

0004 合并nums1, nums2时间复杂度不应该是O(m+n)? #111

hitzhangjie opened this issue Apr 11, 2021 · 3 comments

Comments

@hitzhangjie
Copy link

书中提及说是O(max(m,n)),nums1、nums2都有序,但是不一定nums1中都小于或者大约nums2,
最坏情况下需要完全遍历nums1、nums2吧?那不是O(m+n)?

@hitzhangjie hitzhangjie changed the title 0004 合并nums1, nums2时间复杂度不是O(m+n) 0004 合并nums1, nums2时间复杂度不应该是O(m+n)? Apr 11, 2021
@halfrost
Copy link
Owner

@hitzhangjie 0004 是 Median of Two Sorted Arrays 这道题吧?我刚刚搜了一下,好像没找到你说的 O(max(m,n)),这道题的代码时间复杂度是 O(log min(m,n))),

@hitzhangjie
Copy link
Author

奥,我描述的不清楚,是这里 合并有序数组的操作是 O(max(n,m)) 的,这里的合并应该是O(m+n)?

@halfrost
Copy link
Owner

@hitzhangjie 看到了你说的地方了。你说的是对的。我修改过来了。感谢指出!

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