Skip to content

Commit 2c26b75

Browse files
committed
docs: add Merge k Sorted Lists in the main problem list
1 parent 0cc2367 commit 2c26b75

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/hard/median_of_two_sorted_arrays.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ pub fn find_median_sorted_arrays(nums1: Vec<i32>, nums2: Vec<i32>) -> f64 {
88

99
let half = (nums1.len() + nums2.len() + 1) / 2;
1010
let (m, n) = (nums1.len(), nums2.len());
11-
let (mut low, mut high) = (0, m);
11+
let (mut left, mut right) = (0, m);
1212

13-
while low <= high {
14-
let partition_x = (low + high) / 2;
15-
let partition_y = half - partition_x;
13+
while left <= right {
14+
let partition_x = (left + right) / 2;
15+
let partition_y = half - partition_x;
1616

17-
// Partition_x is always greater than 0
17+
// Partition_x is for m, Partition_y is for n
1818
let max_x = if partition_x == 0 {
1919
i32::MIN
2020
} else {
@@ -27,7 +27,6 @@ pub fn find_median_sorted_arrays(nums1: Vec<i32>, nums2: Vec<i32>) -> f64 {
2727
nums1[partition_x]
2828
};
2929

30-
// Partition_y is always greater than 0
3130
let max_y = if partition_y == 0 {
3231
i32::MIN
3332
} else {
@@ -40,12 +39,13 @@ pub fn find_median_sorted_arrays(nums1: Vec<i32>, nums2: Vec<i32>) -> f64 {
4039
nums2[partition_y]
4140
};
4241

42+
// Three conditions
4343
if max_x <= min_y && max_y <= min_x {
4444
return calculate_median(max_x, max_y, min_x, min_y, m, n);
4545
} else if max_x > min_y {
46-
high = partition_x - 1;
46+
right = partition_x - 1;
4747
} else {
48-
low = partition_x + 1;
48+
left = partition_x + 1;
4949
}
5050
}
5151
0.0

src/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
- [x] [981. Time based key-value store](../src/medium/time_based_key_value_store.rs) -> [Problem Description](../src/medium/readme.md#981-time-based-key-value-store)
7070
- [Hard](../src/hard)
7171
- [x] [4. Median of two sorted arrays](../src/hard/median_of_two_sorted_arrays.rs) -> [Problem Description](../src/hard/readme.md#4-median-of-two-sorted-arrays)
72+
- [ ] [23. Merge k sorted lists](../src/hard/merge_k_sorted_lists.rs) -> [Problem Description](../src/hard/readme.md#23-merge-k-sorted-lists)
7273
- [x] [42. Trapping rain water](../src/hard/trapping_rain_water.rs) -> [Problem Description](../src/hard/readme.md#42-trapping-rain-water)
7374
- [x] [76. Minimum window substring](../src/hard/minimum_window_substring.rs) -> [Problem Description](../src/hard/readme.md#76-minimum-window-substring)
7475
- [x] [84. Largest rectangle in histogram](../src/hard/largest_rectangle_in_histogram.rs) -> [Problem Description](../src/hard/readme.md#84-largest-rectangle-in-histogram)

theory/categories/3.linked_list/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
- [x] [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | Medium | [Solution](../../../src/medium/add_two_numbers.rs)
3737
- [x] [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) | Medium | [Solution](../../../src/medium/find_the_duplicate_number.rs) | [Problem Description](../../../src/medium/readme.md#287-find-the-duplicate-number)
3838
- [x] [LRU Cache](https://leetcode.com/problems/lru-cache/) | Medium | [Solution](../../../src/medium/lru_cache.rs) | [Problem Description](../../../src/medium/readme.md#146-lru-cache)
39-
- [ ] [Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) | Hard | [Solution](../../../src/hard/merge_k_sorted_lists.rs)
39+
- [ ] [Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) | Hard | [Solution](../../../src/hard/merge_k_sorted_lists.rs) | [Problem Description](../../../src/hard/readme.md#23-merge-k-sorted-lists)
4040
- [ ] [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/) | Hard | [Solution](../../../src/hard/reverse_nodes_in_k_group.rs)
4141

4242
Category: `Linked List`
4343
Created on: 2023-08-22 01:00:00
44-
Last modified on: 2023-09-30 12:25:00
44+
Last modified on: 2023-10-05 21:23:00
4545
Status: In Progress
4646
Author: [David Bujosa](https://github.com/bujosa)

0 commit comments

Comments
 (0)