diff options
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | 0001/Cargo.lock (renamed from rust/Cargo.lock) | 2 | ||||
| -rw-r--r-- | 0001/Cargo.toml (renamed from rust/Cargo.toml) | 2 | ||||
| -rw-r--r-- | 0001/src/main.rs (renamed from rust/src/bin/p0001.rs) | 0 | ||||
| -rw-r--r-- | 0002/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0002/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0002/src/main.rs (renamed from rust/src/bin/p0002.rs) | 41 | ||||
| -rw-r--r-- | 0003/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0003/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0003/src/main.rs (renamed from rust/src/bin/p0003.rs) | 0 | ||||
| -rw-r--r-- | 0004/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0004/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0004/src/main.rs (renamed from rust/src/bin/p0004.rs) | 1 | ||||
| -rw-r--r-- | 0005/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0005/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0005/src/main.rs (renamed from rust/src/bin/p0005.rs) | 0 | ||||
| -rw-r--r-- | 0006/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0006/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0006/src/main.rs (renamed from rust/src/bin/p0006.rs) | 0 | ||||
| -rw-r--r-- | 0009/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0009/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0009/src/main.rs (renamed from rust/src/bin/p0009.rs) | 0 | ||||
| -rw-r--r-- | 0013/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0013/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0013/src/main.rs (renamed from rust/src/bin/p0013.rs) | 0 | ||||
| -rw-r--r-- | 0014/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0014/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0014/src/main.rs (renamed from rust/src/bin/p0014.rs) | 0 | ||||
| -rw-r--r-- | 0021/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0021/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0021/src/main.rs (renamed from rust/src/bin/p0021.rs) | 42 | ||||
| -rw-r--r-- | 0026/main.c (renamed from c/0026/main.c) | 0 | ||||
| -rw-r--r-- | 0027/main.c (renamed from c/0027/main.c) | 0 | ||||
| -rw-r--r-- | 0028/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0028/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0028/src/main.rs (renamed from rust/src/bin/p0028.rs) | 0 | ||||
| -rw-r--r-- | 0035/main.c (renamed from c/0035/main.c) | 0 | ||||
| -rw-r--r-- | 0058/main.c (renamed from c/0058/main.c) | 0 | ||||
| -rw-r--r-- | 0066/main.c (renamed from c/0066/main.c) | 0 | ||||
| -rw-r--r-- | 0067/main.c (renamed from c/0067/main.c) | 0 | ||||
| -rw-r--r-- | 0069/main.c (renamed from c/0069/main.c) | 0 | ||||
| -rw-r--r-- | 0070/main.c (renamed from c/0070/main.c) | 0 | ||||
| -rw-r--r-- | rust/src/lib.rs | 1 | ||||
| -rw-r--r-- | rust/src/list.rs | 40 | ||||
| -rw-r--r-- | rust/src/main.rs | 3 |
45 files changed, 215 insertions, 51 deletions
@@ -1,3 +1,3 @@ -rust/target -rust/.idea +*/target +*/.idea a.out
\ No newline at end of file diff --git a/rust/Cargo.lock b/0001/Cargo.lock index d5eb8a3..cf4788e 100644 --- a/rust/Cargo.lock +++ b/0001/Cargo.lock @@ -3,5 +3,5 @@ version = 3 [[package]] -name = "leetcode" +name = "p1" version = "0.1.0" diff --git a/rust/Cargo.toml b/0001/Cargo.toml index dedfbd3..47a9ccd 100644 --- a/rust/Cargo.toml +++ b/0001/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "leetcode" +name = "p1" version = "0.1.0" edition = "2021" diff --git a/rust/src/bin/p0001.rs b/0001/src/main.rs index 70128c9..70128c9 100644 --- a/rust/src/bin/p0001.rs +++ b/0001/src/main.rs diff --git a/0002/Cargo.lock b/0002/Cargo.lock new file mode 100644 index 0000000..2607e79 --- /dev/null +++ b/0002/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p2" +version = "0.1.0" diff --git a/0002/Cargo.toml b/0002/Cargo.toml new file mode 100644 index 0000000..5253ff9 --- /dev/null +++ b/0002/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p2" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0002.rs b/0002/src/main.rs index d8acf94..2cc01f3 100644 --- a/rust/src/bin/p0002.rs +++ b/0002/src/main.rs @@ -1,4 +1,43 @@ -use leetcode::list::*; +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option<Box<ListNode>> +} +// +impl ListNode { + #[inline] + pub fn new(val: i32) -> Self { + ListNode { + next: None, + val + } + } +} + +pub fn vector2list(vec: Vec<i32>) -> Option<Box<ListNode>> { + let mut result: Option<Box<ListNode>> = None; + for i in 0..vec.len() { + let mut new_result = Some(Box::new(ListNode::new(vec[vec.len() - i - 1]))); + new_result.as_mut().unwrap().next = result; + result = new_result; + } + result +} + +pub fn list2vector(lst: Option<Box<ListNode>>) -> Vec<i32> { + let mut result: Vec<i32> = Vec::new(); + let mut cur = &lst; + loop { + match cur { + None => break, + Some(node) => { + result.push(node.val); + cur = &node.next; + }, + } + } + result +} struct Solution {} diff --git a/0003/Cargo.lock b/0003/Cargo.lock new file mode 100644 index 0000000..86306ae --- /dev/null +++ b/0003/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p3" +version = "0.1.0" diff --git a/0003/Cargo.toml b/0003/Cargo.toml new file mode 100644 index 0000000..f8264b5 --- /dev/null +++ b/0003/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p3" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0003.rs b/0003/src/main.rs index 7293c13..7293c13 100644 --- a/rust/src/bin/p0003.rs +++ b/0003/src/main.rs diff --git a/0004/Cargo.lock b/0004/Cargo.lock new file mode 100644 index 0000000..c370f39 --- /dev/null +++ b/0004/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p4" +version = "0.1.0" diff --git a/0004/Cargo.toml b/0004/Cargo.toml new file mode 100644 index 0000000..264a6d2 --- /dev/null +++ b/0004/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p4" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0004.rs b/0004/src/main.rs index 2925500..bab223b 100644 --- a/rust/src/bin/p0004.rs +++ b/0004/src/main.rs @@ -55,7 +55,6 @@ impl Solution { let mut mid2: i32 = 0; loop { if left > right { break; } - println!("left: {}, right: {}", left, right); mid = (left + right) / 2; mid2 = (n1.len() + n2.len()) as i32 / 2 - (1 + mid) - 1; if mid2 < -1 { diff --git a/0005/Cargo.lock b/0005/Cargo.lock new file mode 100644 index 0000000..832b266 --- /dev/null +++ b/0005/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p5" +version = "0.1.0" diff --git a/0005/Cargo.toml b/0005/Cargo.toml new file mode 100644 index 0000000..b6d131b --- /dev/null +++ b/0005/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p5" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0005.rs b/0005/src/main.rs index 01b368d..01b368d 100644 --- a/rust/src/bin/p0005.rs +++ b/0005/src/main.rs diff --git a/0006/Cargo.lock b/0006/Cargo.lock new file mode 100644 index 0000000..7f8c116 --- /dev/null +++ b/0006/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p6" +version = "0.1.0" diff --git a/0006/Cargo.toml b/0006/Cargo.toml new file mode 100644 index 0000000..967e5aa --- /dev/null +++ b/0006/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p6" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0006.rs b/0006/src/main.rs index 92e4b6f..92e4b6f 100644 --- a/rust/src/bin/p0006.rs +++ b/0006/src/main.rs diff --git a/0009/Cargo.lock b/0009/Cargo.lock new file mode 100644 index 0000000..adc6c9d --- /dev/null +++ b/0009/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p9" +version = "0.1.0" diff --git a/0009/Cargo.toml b/0009/Cargo.toml new file mode 100644 index 0000000..7b36dc9 --- /dev/null +++ b/0009/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p9" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0009.rs b/0009/src/main.rs index 4ecb473..4ecb473 100644 --- a/rust/src/bin/p0009.rs +++ b/0009/src/main.rs diff --git a/0013/Cargo.lock b/0013/Cargo.lock new file mode 100644 index 0000000..5b1a871 --- /dev/null +++ b/0013/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p13" +version = "0.1.0" diff --git a/0013/Cargo.toml b/0013/Cargo.toml new file mode 100644 index 0000000..ce536c4 --- /dev/null +++ b/0013/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p13" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0013.rs b/0013/src/main.rs index b5f8a62..b5f8a62 100644 --- a/rust/src/bin/p0013.rs +++ b/0013/src/main.rs diff --git a/0014/Cargo.lock b/0014/Cargo.lock new file mode 100644 index 0000000..83c9b24 --- /dev/null +++ b/0014/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p14" +version = "0.1.0" diff --git a/0014/Cargo.toml b/0014/Cargo.toml new file mode 100644 index 0000000..23404ea --- /dev/null +++ b/0014/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p14" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0014.rs b/0014/src/main.rs index e85ef8f..e85ef8f 100644 --- a/rust/src/bin/p0014.rs +++ b/0014/src/main.rs diff --git a/0021/Cargo.lock b/0021/Cargo.lock new file mode 100644 index 0000000..2f6432e --- /dev/null +++ b/0021/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p21" +version = "0.1.0" diff --git a/0021/Cargo.toml b/0021/Cargo.toml new file mode 100644 index 0000000..a23a66a --- /dev/null +++ b/0021/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p21" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0021.rs b/0021/src/main.rs index d0ce9e6..a53e20c 100644 --- a/rust/src/bin/p0021.rs +++ b/0021/src/main.rs @@ -1,4 +1,44 @@ -use leetcode::list::*; +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option<Box<ListNode>> +} +// +impl ListNode { + #[inline] + pub fn new(val: i32) -> Self { + ListNode { + next: None, + val + } + } +} + +pub fn vector2list(vec: Vec<i32>) -> Option<Box<ListNode>> { + let mut result: Option<Box<ListNode>> = None; + for i in 0..vec.len() { + let mut new_result = Some(Box::new(ListNode::new(vec[vec.len() - i - 1]))); + new_result.as_mut().unwrap().next = result; + result = new_result; + } + result +} + +pub fn list2vector(lst: Option<Box<ListNode>>) -> Vec<i32> { + let mut result: Vec<i32> = Vec::new(); + let mut cur = &lst; + loop { + match cur { + None => break, + Some(node) => { + result.push(node.val); + cur = &node.next; + }, + } + } + result +} + impl Solution { pub fn merge_two_lists(list1: Option<Box<ListNode>>, list2: Option<Box<ListNode>>) -> Option<Box<ListNode>> { diff --git a/c/0026/main.c b/0026/main.c index 27f94e0..27f94e0 100644 --- a/c/0026/main.c +++ b/0026/main.c diff --git a/c/0027/main.c b/0027/main.c index dd5ab1b..dd5ab1b 100644 --- a/c/0027/main.c +++ b/0027/main.c diff --git a/0028/Cargo.lock b/0028/Cargo.lock new file mode 100644 index 0000000..270e521 --- /dev/null +++ b/0028/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p28" +version = "0.1.0" diff --git a/0028/Cargo.toml b/0028/Cargo.toml new file mode 100644 index 0000000..c78abd7 --- /dev/null +++ b/0028/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p28" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/src/bin/p0028.rs b/0028/src/main.rs index c830ac4..c830ac4 100644 --- a/rust/src/bin/p0028.rs +++ b/0028/src/main.rs diff --git a/c/0035/main.c b/0035/main.c index 287885a..287885a 100644 --- a/c/0035/main.c +++ b/0035/main.c diff --git a/c/0058/main.c b/0058/main.c index 6aff206..6aff206 100644 --- a/c/0058/main.c +++ b/0058/main.c diff --git a/c/0066/main.c b/0066/main.c index b01eb8b..b01eb8b 100644 --- a/c/0066/main.c +++ b/0066/main.c diff --git a/c/0067/main.c b/0067/main.c index 900c685..900c685 100644 --- a/c/0067/main.c +++ b/0067/main.c diff --git a/c/0069/main.c b/0069/main.c index 86aab4a..86aab4a 100644 --- a/c/0069/main.c +++ b/0069/main.c diff --git a/c/0070/main.c b/0070/main.c index 143eeb3..143eeb3 100644 --- a/c/0070/main.c +++ b/0070/main.c diff --git a/rust/src/lib.rs b/rust/src/lib.rs deleted file mode 100644 index 651aed7..0000000 --- a/rust/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod list;
\ No newline at end of file diff --git a/rust/src/list.rs b/rust/src/list.rs deleted file mode 100644 index d033cfe..0000000 --- a/rust/src/list.rs +++ /dev/null @@ -1,40 +0,0 @@ -#[derive(PartialEq, Eq, Clone, Debug)] -pub struct ListNode { - pub val: i32, - pub next: Option<Box<ListNode>> -} -// -impl ListNode { - #[inline] - pub fn new(val: i32) -> Self { - ListNode { - next: None, - val - } - } -} - -pub fn vector2list(vec: Vec<i32>) -> Option<Box<ListNode>> { - let mut result: Option<Box<ListNode>> = None; - for i in 0..vec.len() { - let mut new_result = Some(Box::new(ListNode::new(vec[vec.len() - i - 1]))); - new_result.as_mut().unwrap().next = result; - result = new_result; - } - result -} - -pub fn list2vector(lst: Option<Box<ListNode>>) -> Vec<i32> { - let mut result: Vec<i32> = Vec::new(); - let mut cur = &lst; - loop { - match cur { - None => break, - Some(node) => { - result.push(node.val); - cur = &node.next; - }, - } - } - result -}
\ No newline at end of file diff --git a/rust/src/main.rs b/rust/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/rust/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} |
