From ea455b55772b3102c4626453d3e2f0669f775b09 Mon Sep 17 00:00:00 2001 From: li-chx Date: Thu, 2 Oct 2025 17:03:18 +0800 Subject: [PATCH] =?UTF-8?q?3100.=20=E6=8D=A2=E6=B0=B4=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?II?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9b2d341..e78631f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,17 +2,18 @@ mod arr; struct Solution {} impl Solution { - pub fn triangular_sum(mut nums: Vec) -> i32 { - for i in 0.. nums.len() - 1 { - for j in 0..nums.len() - 1 - i { - nums[j] = (nums[j] + nums[j + 1]) % 10; - } + 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; + ans += 1; + num_bottles += 1; + num_exchange += 1; } - nums[0] + ans } } fn main() { - let arr = vec![1,2,3,4,5]; - println!("{}", Solution::triangular_sum(arr)); + println!("{}", Solution::max_bottles_drunk(10,3)); }