From 0564edc18a705efd9d5480d8d5d099b7bd3f6173 Mon Sep 17 00:00:00 2001 From: yassine naanani <27584700+K11E3R@users.noreply.github.com> Date: Sun, 7 Jul 2024 20:30:10 +0200 Subject: [PATCH 1/3] Solution.rs Solution with rust --- .../3100-3199/3100.Water Bottles II/Solution.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 solution/3100-3199/3100.Water Bottles II/Solution.rs 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..bf6e5da737565 --- /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 c6e2a98060a5a1560a220689603d861ee5b07002 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 8 Jul 2024 08:36:42 +0800 Subject: [PATCH 2/3] Update README.md --- .../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..cd42288b095a4 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 + } +} +``` + From b077a3914577230c7c508d6f9b7361d128cce22b Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 8 Jul 2024 08:36:56 +0800 Subject: [PATCH 3/3] Update README_EN.md --- .../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..e42d998765acf 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 { } ``` +#### 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 + } +} +``` +