8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ad7d027 commit 9b2d919Copy full SHA for 9b2d919
src/coin_change.rs
@@ -0,0 +1,19 @@
1
+pub struct Solution {}
2
+impl Solution {
3
+ pub fn coin_change(coins: Vec<i32>, amount: i32) -> i32 {
4
+ let mut mem = vec![amount + 1; amount as usize + 1];
5
+ mem[0] = 0;
6
+
7
+ for i in 1..amount + 1 {
8
+ for c in &coins {
9
+ if i - c >= 0 {
10
+ mem[i as usize] = std::cmp::min(mem[i as usize], 1 + mem[(i - c) as usize]);
11
+ }
12
13
14
+ if mem[amount as usize] != amount + 1 {
15
+ return mem[amount as usize];
16
17
+ -1
18
19
+}
src/main.rs
@@ -1,2 +1,2 @@
-mod decode_ways;
3B37
+mod coin_change;
fn main() {}
0 commit comments