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

Commit 48020d2

Browse files
committed
fix bug in solution 0004
Math.min(nums2[i], nums1[j]) -> Math.min(nums2[j], nums1[i])
1 parent 7e600d7 commit 48020d2

File tree

1 file changed

+2
-4
lines changed
  • solution/0004.Median of Two Sorted Arrays

1 file changed

+2
-4
lines changed

‎solution/0004.Median of Two Sorted Arrays/README.md‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class Solution {
5555
int len1 = nums1.length;
5656
int len2 = nums2.length;
5757

58-
// 确保 len1 不大于 len2
5958
if (len1 > len2) {
6059
int[] tmp = nums1;
6160
nums1 = nums2;
@@ -69,10 +68,9 @@ class Solution {
6968
int max = len1;
7069

7170
int m = (len1 + len2 + 1) / 2;
72-
71+
7372
while (min <= max) {
7473
int i = (min + max) / 2;
75-
7674
int j = m - i;
7775

7876
if (i > min && nums1[i - 1] > nums2[j]) {
@@ -87,7 +85,7 @@ class Solution {
8785
return maxLeft;
8886
}
8987

90-
int minRight = i == len1 ? nums2[j] : j == len2 ? nums1[i] : Math.min(nums2[i], nums1[j]);
88+
int minRight = i == len1 ? nums2[j] : j == len2 ? nums1[i] : Math.min(nums2[j], nums1[i]);
9189

9290
return (maxLeft + minRight) / 2.0;
9391

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /