8000 update · jhideki/rust_leetcode@9b2d919 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b2d919

Browse files
committed
update
1 parent ad7d027 commit 9b2d919

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/coin_change.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
mod decode_ways;
3B37 1+
mod coin_change;
22
fn main() {}

0 commit comments

Comments
 (0)
0