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 + } +} +``` + 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 + } +} +``` + 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 + } +}