Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 20, 2019 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/d6e21eeca86b49cc495350c3268558d5 to your computer and use it in GitHub Desktop.
Save rust-play/d6e21eeca86b49cc495350c3268558d5 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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