From 89146b7fc34a070b89dcacb06eb80b50fa27ed3b Mon Sep 17 00:00:00 2001 From: xblakicex Date: Fri, 13 Jan 2023 19:01:51 +0100 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=90=9E=20fix(computational=5Fcomple?= =?UTF-8?q?xity):=20fix=20some=20rust=20cmpl=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chapter_computational_complexity/time_complexity.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/codes/rust/chapter_computational_complexity/time_complexity.rs b/codes/rust/chapter_computational_complexity/time_complexity.rs index a6aa60b31..b18f19ade 100644 --- a/codes/rust/chapter_computational_complexity/time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/time_complexity.rs @@ -1,4 +1,10 @@ -#![allow(unused_variables)] +/** + * File: time_complexity.cpp + * Created Time: 2023-01-10 + * Author: xBLACICEx (xBLACKICEx@outlook.com ) + */ + +#[allow(unused_variables)] /* 常数阶 */ fn constant(n: i32) -> i32 { From 705fc86e897b3947c91a08eb3d6385cf86f704dc Mon Sep 17 00:00:00 2001 From: xblakicex Date: Fri, 13 Jan 2023 19:02:42 +0100 Subject: [PATCH 02/12] =?UTF-8?q?=E2=9C=A8=20feat(worst=5Fbest=5Ftime=5Fco?= =?UTF-8?q?mplexity):=20add=20rust=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worst_best_time_complexity.rs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs diff --git a/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs new file mode 100644 index 000000000..23c2d646e --- /dev/null +++ b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs @@ -0,0 +1,43 @@ +// rand = "0.8.5" +/** + * File: time_complexity.cpp + * Created Time: 2023-01-13 + * Author: xBLACICEx (xBLACKICEx@outlook.com ) + */ + +// to compilse and run this singile file need: +// 1. cargo install cargo-single +// 2. cargo single run worst_best_time_complexity.rs + +use rand::seq::SliceRandom; +use rand::thread_rng; + +/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ +fn random_numbers(n: i32) -> Vec { + // 生成数组 nums = { 1, 2, 3, ..., n } + let mut nums = (1..n + 1).collect::>(); + // 随机打乱数组元素 + nums.shuffle(&mut thread_rng()); + nums +} + +/* 查找数组 nums 中数字 1 所在索引 */ +fn find_one(nums: &[i32]) -> Option { + for i in 0..nums.len() { + if nums[i] == 1 { + return Some(i); + } + } + None +} + +/* Driver Code */ +fn main() { + for _ in 0..10 { + let n = 100; + let nums = random_numbers(n); + let index = find_one(&nums); + println!("\n数组 [ 1, 2, ..., n ] 被打乱后 = {:?}", nums); + println!("数字 1 的索引为 {:?}", index); + } +} \ No newline at end of file From d0359378f3349ed033d5956c1d7ff0143cc40836 Mon Sep 17 00:00:00 2001 From: xblakicex Date: Fri, 13 Jan 2023 19:04:06 +0100 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=90=B3=20chore(codes):=20add=20carg?= =?UTF-8?q?o=20for=20rust=20codes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/rust/.gitignore | 3 ++ codes/rust/Cargo.lock | 75 +++++++++++++++++++++++++++++++++++++++++++ codes/rust/Cargo.toml | 14 ++++++++ 3 files changed, 92 insertions(+) create mode 100644 codes/rust/.gitignore create mode 100644 codes/rust/Cargo.lock create mode 100644 codes/rust/Cargo.toml diff --git a/codes/rust/.gitignore b/codes/rust/.gitignore new file mode 100644 index 000000000..106fe28c3 --- /dev/null +++ b/codes/rust/.gitignore @@ -0,0 +1,3 @@ +**/target +**/worst_best_time_complexity/ +**/time_complexity/ \ No newline at end of file diff --git a/codes/rust/Cargo.lock b/codes/rust/Cargo.lock new file mode 100644 index 000000000..ae2b69a86 --- /dev/null +++ b/codes/rust/Cargo.lock @@ -0,0 +1,75 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chapter_computational_complexity" +version = "0.1.0" +dependencies = [ + "rand", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/codes/rust/Cargo.toml b/codes/rust/Cargo.toml new file mode 100644 index 000000000..d9ff563c8 --- /dev/null +++ b/codes/rust/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "chapter_computational_complexity" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "time_complexity" +path = "chapter_computational_complexity/time_complexity.rs" + +[[bin]] +name = "worst_best_time_complexity" +path = "chapter_computational_complexity/worst_best_time_complexity.rs" +[dependencies] +rand = "0.8.5" From d710a3ffdf5b045cab2c421fd0a0bc72280e938e Mon Sep 17 00:00:00 2001 From: xblakicex Date: Fri, 13 Jan 2023 20:37:44 +0100 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=90=9E=20fix(codes/time=5Fcomplexit?= =?UTF-8?q?y):=20fix=20=20rust=20attribut=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rust/chapter_computational_complexity/time_complexity.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/codes/rust/chapter_computational_complexity/time_complexity.rs b/codes/rust/chapter_computational_complexity/time_complexity.rs index b18f19ade..066dbac6a 100644 --- a/codes/rust/chapter_computational_complexity/time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/time_complexity.rs @@ -1,10 +1,9 @@ +#![allow(unused_variables)] /** * File: time_complexity.cpp * Created Time: 2023-01-10 * Author: xBLACICEx (xBLACKICEx@outlook.com ) - */ - -#[allow(unused_variables)] +*/ /* 常数阶 */ fn constant(n: i32) -> i32 { From e99d23690e8fcb41ff92c807252b7499539a4390 Mon Sep 17 00:00:00 2001 From: xblakicex Date: Fri, 13 Jan 2023 20:41:18 +0100 Subject: [PATCH 05/12] =?UTF-8?q?=E2=9C=A8=20feat(space=5Fcomplexity):=20a?= =?UTF-8?q?dd=20rust=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_complexity.rs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 codes/rust/chapter_computational_complexity/space_complexity.rs diff --git a/codes/rust/chapter_computational_complexity/space_complexity.rs b/codes/rust/chapter_computational_complexity/space_complexity.rs new file mode 100644 index 000000000..a65ebb748 --- /dev/null +++ b/codes/rust/chapter_computational_complexity/space_complexity.rs @@ -0,0 +1,70 @@ +#![allow(unused_variables)] +/** + * File: space_complexity.cpp + * Created Time: 2023-01-13 + * Author: xBLACICEx (xBLACKICEx@outlook.com ) +*/ + +use std::collections::HashMap; + +/* 函数 */ +fn func() { + // do something +} + +/* 常数阶 */ +fn constant(n: i32) { + // TODO +} + +/* 线性阶 */ +fn linear(n: i32) { + // 长度为 n 的数组占用 O(n) 空间 + let nums = vec![0; n as usize]; + let map: HashMap<_, _> = (0..n).map(|i| (i, format!("{}", i))).collect(); +} + +/* 线性阶(递归实现) */ +fn linear_recur(n: i32) { + println!("递归 n = {n}"); + if n == 1 { + return; + } + linear_recur(n - 1); +} + +/* 平方阶 */ +fn quadratic(n: i32) { + // 二维列表占用 O(n^2) 空间 + let num_matrix = vec![vec![0; n as usize]; n as usize]; +} + +/* 平方阶(递归实现) */ +fn quadratic_recur(n: i32) -> i32 { + if n <= 0 { + return 0 + } + // 数组 nums 长度为 n, n-1, ..., 2, 1 + let nums = vec![0; n as usize]; + println!("递归 n = {n} 中的 nums 长度 = {}", nums.len()); + return quadratic_recur(n - 1); +} + +fn build_tree(n: usize) { + // TODO +} + +fn main() { + let n = 5; + /* 常数阶 */ + constant(n); + /* 线性阶 */ + linear(n); + linear_recur(n); + /* 平方阶 */ + quadratic(n); + quadratic_recur(n); + /* 指数阶 */ + // let root = build_tree(n); + // print_tree(root); +} \ No newline at end of file From c20ebb4411487e91c13787f34f7b23501d4f918c Mon Sep 17 00:00:00 2001 From: xblakicex Date: Fri, 13 Jan 2023 20:51:36 +0100 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=8C=88=20style(space=5Fcomplexity):?= =?UTF-8?q?=20add=20Add=20todo=20comments=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rust/chapter_computational_complexity/space_complexity.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codes/rust/chapter_computational_complexity/space_complexity.rs b/codes/rust/chapter_computational_complexity/space_complexity.rs index a65ebb748..37064fcd3 100644 --- a/codes/rust/chapter_computational_complexity/space_complexity.rs +++ b/codes/rust/chapter_computational_complexity/space_complexity.rs @@ -21,6 +21,9 @@ fn constant(n: i32) { fn linear(n: i32) { // 长度为 n 的数组占用 O(n) 空间 let nums = vec![0; n as usize]; + // 长度为 n 的列表占用 O(n) 空间 + // TODO + // 长度为 n 的哈希表占用 O(n) 空间 let map: HashMap<_, _> = (0..n).map(|i| (i, format!("{}", i))).collect(); } From a5425b6d9b0235af37674b8956f8fba5be117fd4 Mon Sep 17 00:00:00 2001 From: xblakicex Date: Sat, 14 Jan 2023 14:45:52 +0100 Subject: [PATCH 07/12] =?UTF-8?q?=E2=9C=A8=20feat(codes/rust):=20add=20lee?= =?UTF-8?q?tcode=5Ftwo=5Fsum.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leetcode_two_sum.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 codes/rust/chapter_computational_complexity/leetcode_two_sum.rs diff --git a/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs b/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs new file mode 100644 index 000000000..95d264b89 --- /dev/null +++ b/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs @@ -0,0 +1,47 @@ +/** + * File: leetcode_two_sum.rs + * Created Time: 2023-01-14 + * Author: xBLACICEx (xBLACKICEx@outlook.com ) +*/ + +use std::collections::HashMap; +struct SolutionBruteForce; +struct SolutionHashMap; + +impl SolutionBruteForce { + pub fn two_sum(nums: &Vec, target: i32) -> Vec { + for i in 0..nums.len() - 1 { + for j in i + 1..nums.len() { + if nums[i] + nums[j] == target { + return vec![i as i32, j as i32]; + } + } + } + vec![] + } +} + +impl SolutionHashMap { + pub fn two_sum(nums: &Vec, target: i32) -> Vec { + let mut hm = HashMap::new(); + + for (i, n) in nums.iter().enumerate() { + match hm.get(&(target - n)) { + Some(v) => return vec![*v as i32, i as i32], + None => hm.insert(n, i) + }; + } + vec![] + } +} + +fn main() { + let nums = vec![2,7,11,15]; + let target = 9; + + let res = SolutionBruteForce::two_sum(&nums, target); + println!("方法一 res = {:?}", res); + + let res = SolutionHashMap::two_sum(&nums, target); + println!("方法二 res = {:?}", res); +} \ No newline at end of file From 28e9e4ceb6612750e65818f141c6340ff22a2422 Mon Sep 17 00:00:00 2001 From: xblakicex Date: Sat, 14 Jan 2023 18:25:18 +0100 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=8C=88=20style(codes/rust):=20add?= =?UTF-8?q?=20miss=20comment=20in=20leetcode=5Ftwo=5Fsums=20and=20time=5Fc?= =?UTF-8?q?omplexity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chapter_computational_complexity/leetcode_two_sum.rs | 5 ++++- .../rust/chapter_computational_complexity/time_complexity.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs b/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs index 95d264b89..f6d457309 100644 --- a/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs +++ b/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs @@ -35,13 +35,16 @@ impl SolutionHashMap { } } +// Driver Code fn main() { + // ======= Test Case ======= let nums = vec![2,7,11,15]; let target = 9; + // 方法一 let res = SolutionBruteForce::two_sum(&nums, target); println!("方法一 res = {:?}", res); - + // 方法二 let res = SolutionHashMap::two_sum(&nums, target); println!("方法二 res = {:?}", res); } \ No newline at end of file diff --git a/codes/rust/chapter_computational_complexity/time_complexity.rs b/codes/rust/chapter_computational_complexity/time_complexity.rs index 066dbac6a..942ba471d 100644 --- a/codes/rust/chapter_computational_complexity/time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/time_complexity.rs @@ -15,6 +15,7 @@ fn constant(n: i32) -> i32 { count } +/* 线性阶 */ fn linear(n: i32) -> i32 { let mut count = 0; for _ in 0..n { From 16e4af08b661f05ac23f6bd6be2369adad2ac194 Mon Sep 17 00:00:00 2001 From: xblakicex Date: Sun, 15 Jan 2023 17:47:28 +0100 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=8C=88=20style(codes/rust):=20fix?= =?UTF-8?q?=20comment=20style=20and=20miss=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chapter_computational_complexity/leetcode_two_sum.rs | 2 +- .../chapter_computational_complexity/space_complexity.rs | 6 +++--- .../chapter_computational_complexity/time_complexity.rs | 7 ++++--- .../worst_best_time_complexity.rs | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs b/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs index f6d457309..821d52c92 100644 --- a/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs +++ b/codes/rust/chapter_computational_complexity/leetcode_two_sum.rs @@ -1,7 +1,7 @@ /** * File: leetcode_two_sum.rs * Created Time: 2023-01-14 - * Author: xBLACICEx (xBLACKICEx@outlook.com ) + * Author: xBLACICEx (xBLACKICEx@outlook.com) */ use std::collections::HashMap; diff --git a/codes/rust/chapter_computational_complexity/space_complexity.rs b/codes/rust/chapter_computational_complexity/space_complexity.rs index 37064fcd3..c2327c786 100644 --- a/codes/rust/chapter_computational_complexity/space_complexity.rs +++ b/codes/rust/chapter_computational_complexity/space_complexity.rs @@ -1,9 +1,9 @@ -#![allow(unused_variables)] /** - * File: space_complexity.cpp + * File: space_complexity.rs * Created Time: 2023-01-13 - * Author: xBLACICEx (xBLACKICEx@outlook.com ) + * Author: xBLACICEx (xBLACKICEx@outlook.com) */ +#[allow(unused_variables)] use std::collections::HashMap; diff --git a/codes/rust/chapter_computational_complexity/time_complexity.rs b/codes/rust/chapter_computational_complexity/time_complexity.rs index 942ba471d..6ddacc5c7 100644 --- a/codes/rust/chapter_computational_complexity/time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/time_complexity.rs @@ -1,9 +1,9 @@ -#![allow(unused_variables)] /** - * File: time_complexity.cpp + * File: time_complexity.rs * Created Time: 2023-01-10 - * Author: xBLACICEx (xBLACKICEx@outlook.com ) + * Author: xBLACICEx (xBLACKICEx@outlook.com) */ +#[allow(unused_variables)] /* 常数阶 */ fn constant(n: i32) -> i32 { @@ -98,6 +98,7 @@ fn logarithmic(mut n: i32) -> i32 { count } +/* 对数阶(递归实现) */ fn log_recur(n: i32) -> i32 { if n <= 1 { return 0; diff --git a/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs index 23c2d646e..179d358d1 100644 --- a/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs @@ -1,10 +1,10 @@ -// rand = "0.8.5" /** - * File: time_complexity.cpp + * File: time_complexity.rs * Created Time: 2023-01-13 - * Author: xBLACICEx (xBLACKICEx@outlook.com ) + * Author: xBLACICEx (xBLACKICEx@outlook.com) */ +// rand = "0.8.5" // to compilse and run this singile file need: // 1. cargo install cargo-single // 2. cargo single run worst_best_time_complexity.rs From 3d4469203bb1752abd4f031b4900840d621745c7 Mon Sep 17 00:00:00 2001 From: xblakicex Date: Sun, 15 Jan 2023 19:01:06 +0100 Subject: [PATCH 10/12] =?UTF-8?q?=F0=9F=90=B3=20chore(computational=5Fcomp?= =?UTF-8?q?lexity):=20temporary=20remove=20space=5Ftime,rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_complexity.rs | 73 ------------------- 1 file changed, 73 deletions(-) delete mode 100644 codes/rust/chapter_computational_complexity/space_complexity.rs diff --git a/codes/rust/chapter_computational_complexity/space_complexity.rs b/codes/rust/chapter_computational_complexity/space_complexity.rs deleted file mode 100644 index c2327c786..000000000 --- a/codes/rust/chapter_computational_complexity/space_complexity.rs +++ /dev/null @@ -1,73 +0,0 @@ -/** - * File: space_complexity.rs - * Created Time: 2023-01-13 - * Author: xBLACICEx (xBLACKICEx@outlook.com) -*/ -#[allow(unused_variables)] - -use std::collections::HashMap; - -/* 函数 */ -fn func() { - // do something -} - -/* 常数阶 */ -fn constant(n: i32) { - // TODO -} - -/* 线性阶 */ -fn linear(n: i32) { - // 长度为 n 的数组占用 O(n) 空间 - let nums = vec![0; n as usize]; - // 长度为 n 的列表占用 O(n) 空间 - // TODO - // 长度为 n 的哈希表占用 O(n) 空间 - let map: HashMap<_, _> = (0..n).map(|i| (i, format!("{}", i))).collect(); -} - -/* 线性阶(递归实现) */ -fn linear_recur(n: i32) { - println!("递归 n = {n}"); - if n == 1 { - return; - } - linear_recur(n - 1); -} - -/* 平方阶 */ -fn quadratic(n: i32) { - // 二维列表占用 O(n^2) 空间 - let num_matrix = vec![vec![0; n as usize]; n as usize]; -} - -/* 平方阶(递归实现) */ -fn quadratic_recur(n: i32) -> i32 { - if n <= 0 { - return 0 - } - // 数组 nums 长度为 n, n-1, ..., 2, 1 - let nums = vec![0; n as usize]; - println!("递归 n = {n} 中的 nums 长度 = {}", nums.len()); - return quadratic_recur(n - 1); -} - -fn build_tree(n: usize) { - // TODO -} - -fn main() { - let n = 5; - /* 常数阶 */ - constant(n); - /* 线性阶 */ - linear(n); - linear_recur(n); - /* 平方阶 */ - quadratic(n); - quadratic_recur(n); - /* 指数阶 */ - // let root = build_tree(n); - // print_tree(root); -} \ No newline at end of file From 4249872e25b67761d0512de06aa90bce86dff99f Mon Sep 17 00:00:00 2001 From: xblakicex Date: Sun, 15 Jan 2023 19:59:17 +0100 Subject: [PATCH 11/12] =?UTF-8?q?=F0=9F=90=B3=20chore(code/rust):=20add=20?= =?UTF-8?q?cargo=20in=20chapier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/rust/Cargo.toml | 17 ++++----------- .../Cargo.toml | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 codes/rust/chapter_computational_complexity/Cargo.toml diff --git a/codes/rust/Cargo.toml b/codes/rust/Cargo.toml index d9ff563c8..91b54bc3b 100644 --- a/codes/rust/Cargo.toml +++ b/codes/rust/Cargo.toml @@ -1,14 +1,5 @@ -[package] -name = "chapter_computational_complexity" -version = "0.1.0" -edition = "2021" -[[bin]] -name = "time_complexity" -path = "chapter_computational_complexity/time_complexity.rs" - -[[bin]] -name = "worst_best_time_complexity" -path = "chapter_computational_complexity/worst_best_time_complexity.rs" -[dependencies] -rand = "0.8.5" +[workspace] +members = [ + "chapter_computational_complexity", +] \ No newline at end of file diff --git a/codes/rust/chapter_computational_complexity/Cargo.toml b/codes/rust/chapter_computational_complexity/Cargo.toml new file mode 100644 index 000000000..acfb2170c --- /dev/null +++ b/codes/rust/chapter_computational_complexity/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "chapter_computational_complexity" +version = "0.1.0" +edition = "2021" + + +[[bin]] +name = "leetcode_two_sum" +path = "leetcode_two_sum.rs" + +[[bin]] +name = "time_complexity" +path = "time_complexity.rs" + +[[bin]] +name = "worst_best_time_complexity" +path = "worst_best_time_complexity.rs" + + +[dependencies] +rand = "0.8.5" From 20dee23141952a4d7185312d56a4dd666add174c Mon Sep 17 00:00:00 2001 From: xblakicex Date: Sun, 15 Jan 2023 20:01:59 +0100 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=8C=88=20style(computational=5Fcomp?= =?UTF-8?q?lexity):=20remove=20cargo-single=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worst_best_time_complexity.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs index 179d358d1..a5a979c58 100644 --- a/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs @@ -4,11 +4,6 @@ * Author: xBLACICEx (xBLACKICEx@outlook.com) */ -// rand = "0.8.5" -// to compilse and run this singile file need: -// 1. cargo install cargo-single -// 2. cargo single run worst_best_time_complexity.rs - use rand::seq::SliceRandom; use rand::thread_rng;