Implemented p22, TODO - implement p23
This commit is contained in:
parent
5c73aefbc4
commit
e57953fd8c
3 changed files with 39 additions and 3 deletions
|
@ -22,3 +22,4 @@ pub mod p19_remove_nth_node_from_end_of_list;
|
||||||
pub mod p20_valid_parentheses;
|
pub mod p20_valid_parentheses;
|
||||||
pub mod p21_merge_two_sorted_lists;
|
pub mod p21_merge_two_sorted_lists;
|
||||||
pub mod p22_generate_parentheses;
|
pub mod p22_generate_parentheses;
|
||||||
|
pub mod p23_merge_k_sorted_lists;
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
pub struct Solution;
|
pub struct Solution;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
// TODO: implement
|
|
||||||
pub fn generate_parenthesis(n: i32) -> Vec<String> {
|
pub fn generate_parenthesis(n: i32) -> Vec<String> {
|
||||||
|
let mut operations = vec![(0, 0, "".to_string())];
|
||||||
return vec![];
|
let mut result = vec![];
|
||||||
|
while let Some((left, right, s)) = operations.pop() {
|
||||||
|
if s.len() == n as usize * 2 {
|
||||||
|
result.push(s);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if left < n { operations.push((left + 1, right, s.clone() + "(")); }
|
||||||
|
if right < left { operations.push((left, right + 1, s + ")")); }
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
src/p23_merge_k_sorted_lists.rs
Normal file
27
src/p23_merge_k_sorted_lists.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use super::linked_list::ListNode;
|
||||||
|
|
||||||
|
pub struct Solution;
|
||||||
|
impl Solution {
|
||||||
|
// TODO: implement
|
||||||
|
pub fn merge_k_lists(lists: Vec<Option<Box<ListNode>>>) -> Option<Box<ListNode>> {
|
||||||
|
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test1() {
|
||||||
|
assert_eq!(Solution::merge_k_lists(vec![
|
||||||
|
list![1,4,5], list![1,3,4], list![2,6]
|
||||||
|
]), list![1,1,2,3,4,4,5,6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test2() {
|
||||||
|
assert_eq!(Solution::merge_k_lists(vec![]), list![]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test3() {
|
||||||
|
assert_eq!(Solution::merge_k_lists(vec![list![]]), list![]);
|
||||||
|
}
|
Loading…
Reference in a new issue