Created
March 20, 2019 02:01
-
-
Save rust-play/d6e21eeca86b49cc495350c3268558d5 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn minimalNumberOfCoins(coins: Vec<i32>, price: i32) -> i32 { | |
let mut dp = vec![100; (price + 1) as usize]; | |
dp[0] = 0; | |
for coin in &coins { | |
for target in coin..price { | |
dp[price as usize] = min(1 + dp[(price - coin) as usize], dp[(price) as usize]) | |
} | |
} | |
return dp[price as usize]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment