Skip to content

Commit 0cc2367

Browse files
committed
docs: add 23 problem description
1 parent 8782a4c commit 0cc2367

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/hard/readme.md

+53
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,59 @@ Put the code below in main.rs and run `cargo run`
4949
println!("result: {:?}", result);
5050
```
5151

52+
# 23. Merge k Sorted Lists
53+
54+
## Description
55+
56+
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
57+
58+
Merge all the linked-lists into one sorted linked-list and return it.
59+
60+
## Examples
61+
62+
Example 1:
63+
64+
```rust
65+
Input: lists = [[1,4,5],[1,3,4],[2,6]]
66+
Output: [1,1,2,3,4,4,5,6]
67+
Explanation: The linked-lists are:
68+
[
69+
1->4->5,
70+
1->3->4,
71+
2->6
72+
]
73+
74+
merging them into one sorted list:
75+
1->1->2->3->4->4->5->6
76+
```
77+
78+
Example 2:
79+
80+
```rust
81+
Input: lists = []
82+
Output: []
83+
```
84+
85+
Example 3:
86+
87+
```rust
88+
Input: lists = [[]]
89+
Output: []
90+
```
91+
92+
## How to Run in main.rs
93+
94+
Put the code below in main.rs and run `cargo run`
95+
96+
```rust
97+
let lists = vec![
98+
ListNode::from_vec(vec![1, 4, 5]),
99+
ListNode::from_vec(vec![1, 3, 4]),
100+
ListNode::from_vec(vec![2, 6]),
101+
];
102+
let result = hard::merge_k_sorted_lists::merge_k_lists(lists);
103+
println!("result: {:?}", result);
104+
```
52105

53106
# 42. Trapping Rain Water
54107

0 commit comments

Comments
 (0)