Skip to content

Commit 43235c9

Browse files
committed
feat: WEEK 04 solution (coin-change)
1 parent 52536d7 commit 43235c9

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

coin-change/tigermint.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun coinChange(coins: IntArray, amount: Int): Int {
3+
val dp = IntArray(amount + 1) { amount + 1 }
4+
dp[0] = 0
5+
6+
for (i in 1..amount) {
7+
for (c in coins) {
8+
if (i - c >= 0) {
9+
dp[i] = minOf(dp[i], dp[i - c] + 1)
10+
}
11+
}
12+
}
13+
14+
return if (dp[amount] > amount) - 1 else dp[amount]
15+
}
16+
}

0 commit comments

Comments
 (0)