Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2103 from fwqaaq/patch-24
Browse files Browse the repository at this point in the history
Update 0518.零钱兑换II.md 优化 Rust
  • Loading branch information
youngyangyang04 authored Jun 8, 2023
2 parents accc97c + 7359063 commit 385b650
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions problems/0518.零钱兑换II.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,18 @@ func change(amount int, coins []int) int {

Rust:
```rust
pub fn change(amount: i32, coins: Vec<i32>) -> i32 {
let amount = amount as usize;
let coins = coins.iter().map(|&c|c as usize).collect::<Vec<usize>>();
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>) -> 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
}
```

Expand Down

0 comments on commit 385b650

Please sign in to comment.