You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/0000-0099/0004-Median-of-two-Sorted-Array.md
+7-10Lines changed: 7 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,6 @@ In this page, we will solve the problem [Median of Two Sorted Arrays](https://le
16
16
17
17
Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return the median of the two sorted arrays.
18
18
19
-
The overall run time complexity should be $O(log (m+n))$.
20
-
21
19
### Example 1
22
20
23
21
```plaintext
@@ -449,7 +447,7 @@ Let's test the solution with the sample test cases:
449
447
Input: nums1 = [1, 3], nums2 = [2]
450
448
Output: 2.00000
451
449
Explanation: merged array = [1, 2, 3] and median is 2.
452
-
````
450
+
```
453
451
</TabItem>
454
452
455
453
<TabItemvalue="TestCase2"label="Case 2">
@@ -738,8 +736,7 @@ Let's test the solution with the sample test cases:
738
736
Input: nums1 = [1, 3], nums2 = [2]
739
737
Output: 2.00000
740
738
Explanation: merged array = [1, 2, 3] and median is 2.
741
-
````
742
-
739
+
```
743
740
</TabItem>
744
741
<TabItemvalue="TestCase2"label="Case 2">
745
742
```plaintext
@@ -790,19 +787,19 @@ The key idea is to use binary search to partition the smaller array in such a wa
790
787
791
788
4.**Boundary Conditions**:
792
789
793
-
- Handle cases where partitions might go out of bounds. If $$ \text{partitionX} $$ is 0, it means there are no elements on the left side of $$ \text{nums1} $$. If $$ \text{partitionX} $$ is $$ x $$, it means there are no elements on the right side of $$ \text{nums1} $$.
790
+
- Handle cases where partitions might go out of bounds. If $$ \text{partitionX} $$ is 0, it means there are no elements on the left side of $$ \text{nums1} $$. If $$ \text{partitionX} $$ is $x$, it means there are no elements on the right side of $$ \text{nums1} $$.
794
791
795
792
5.**Check Valid Partition**:
796
793
797
794
- A valid partition is one where the maximum element on the left side of both partitions is less than or equal to the minimum element on the right side of both partitions:
Here, $$\text{maxX}$$ is the largest element on the left side of $$\text{nums1}$$, $$\text{minX}$$ is the smallest element on the right side of $$\text{nums1}$$, and similarly for $$\text{nums2}$$.
798
+
Here, $\text{maxX}$ is the largest element on the left side of $\text{nums1}$, $\text{minX}$ is the smallest element on the right side of $\text{nums1}$, and similarly for $\text{nums2}$.
802
799
803
800
6.**Calculate the Median**:
804
801
805
-
- If the total number of elements $ (x + y) $ is even, the median is the average of the two middle values:
802
+
- If the total number of elements $$ (x + y) $$ is even, the median is the average of the two middle values:
0 commit comments