From ca2b065b47b546e2dd3350bc9009eaba57e278f1 Mon Sep 17 00:00:00 2001 From: yassine naanani <27584700+K11E3R@users.noreply.github.com> Date: Sun, 7 Jul 2024 20:34:31 +0200 Subject: [PATCH 1/3] ADD rust solution 0ms runtime complexity 2,08mb space complexity --- .../3100.Water Bottles II/README_EN.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/solution/3100-3199/3100.Water Bottles II/README_EN.md b/solution/3100-3199/3100.Water Bottles II/README_EN.md index a255611acad8e..b094fe3ffcd8e 100644 --- a/solution/3100-3199/3100.Water Bottles II/README_EN.md +++ b/solution/3100-3199/3100.Water Bottles II/README_EN.md @@ -155,6 +155,25 @@ function maxBottlesDrunk(numBottles: number, numExchange: number): number { } ``` +#### TypeScript + +```rs +impl Solution { + pub fn max_bottles_drunk(mut num_bottles: i32, mut num_exchange: i32) -> i32 { + let mut ans = num_bottles; + + while num_bottles >= num_exchange { + num_bottles -= num_exchange; + num_exchange += 1; + ans += 1; + num_bottles += 1; + } + + ans + } +} +``` + From ac129518ee4f85e9f05384342d492ca8da58a707 Mon Sep 17 00:00:00 2001 From: yassine naanani <27584700+K11E3R@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:52:08 +0200 Subject: [PATCH 2/3] Rust Commit fix --- .../3100-3199/3100.Water Bottles II/README_EN.md | 4 ++-- .../3100-3199/3100.Water Bottles II/Solution.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 solution/3100-3199/3100.Water Bottles II/Solution.rs diff --git a/solution/3100-3199/3100.Water Bottles II/README_EN.md b/solution/3100-3199/3100.Water Bottles II/README_EN.md index b094fe3ffcd8e..39b69ccf23654 100644 --- a/solution/3100-3199/3100.Water Bottles II/README_EN.md +++ b/solution/3100-3199/3100.Water Bottles II/README_EN.md @@ -155,9 +155,9 @@ function maxBottlesDrunk(numBottles: number, numExchange: number): number { } ``` -#### TypeScript +#### Rust -```rs +```rust impl Solution { pub fn max_bottles_drunk(mut num_bottles: i32, mut num_exchange: i32) -> i32 { let mut ans = num_bottles; diff --git a/solution/3100-3199/3100.Water Bottles II/Solution.rs b/solution/3100-3199/3100.Water Bottles II/Solution.rs new file mode 100644 index 0000000000000..bd9a017a8e805 --- /dev/null +++ b/solution/3100-3199/3100.Water Bottles II/Solution.rs @@ -0,0 +1,14 @@ +impl Solution { + pub fn max_bottles_drunk(mut num_bottles: i32, mut num_exchange: i32) -> i32 { + let mut ans = num_bottles; + + while num_bottles >= num_exchange { + num_bottles -= num_exchange; + num_exchange += 1; + ans += 1; + num_bottles += 1; + } + + ans + } +} From b70731779c4dfd86d30fecfa82b76eb1f2a188c8 Mon Sep 17 00:00:00 2001 From: yassine naanani <27584700+K11E3R@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:54:39 +0200 Subject: [PATCH 3/3] rust solution added to README --- .../3100-3199/3100.Water Bottles II/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/solution/3100-3199/3100.Water Bottles II/README.md b/solution/3100-3199/3100.Water Bottles II/README.md index 798a1a8488b1d..f5cc3f363d7f3 100644 --- a/solution/3100-3199/3100.Water Bottles II/README.md +++ b/solution/3100-3199/3100.Water Bottles II/README.md @@ -156,6 +156,25 @@ function maxBottlesDrunk(numBottles: number, numExchange: number): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn max_bottles_drunk(mut num_bottles: i32, mut num_exchange: i32) -> i32 { + let mut ans = num_bottles; + + while num_bottles >= num_exchange { + num_bottles -= num_exchange; + num_exchange += 1; + ans += 1; + num_bottles += 1; + } + + ans + } +} +``` +