diff --git "a/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" "b/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" index c208754f77..8da351148b 100644 --- "a/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" +++ "b/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" @@ -282,17 +282,18 @@ func change(amount int, coins []int) int { Rust: ```rust -pub fn change(amount: i32, coins: Vec) -> i32 { - let amount = amount as usize; - let coins = coins.iter().map(|&c|c as usize).collect::>(); - let mut dp = vec![0usize; amount + 1]; - dp[0] = 1; - for i in 0..coins.len() { - for j in coins[i]..=amount { - dp[j] += dp[j - coins[i]]; +impl Solution { + pub fn change(amount: i32, coins: Vec) -> i32 { + let amount = amount as usize; + let mut dp = vec![0; amount + 1]; + dp[0] = 1; + for coin in coins { + for j in coin as usize..=amount { + dp[j] += dp[j - coin as usize]; + } } + dp[amount] } - dp[amount] as i32 } ```