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 2f0e23e commit 63ddb7cCopy full SHA for 63ddb7c
coin-change/WhiteHyun.swift
@@ -0,0 +1,23 @@
1
+//
2
+// 322. Coin Change
3
+// https://leetcode.com/problems/coin-change/description/
4
+// Dale-Study
5
6
+// Created by WhiteHyun on 2024/07/14.
7
8
+
9
+class Solution {
10
+ func coinChange(_ coins: [Int], _ amount: Int) -> Int {
11
+ var dp: [Int] = .init(repeating: .max, count: amount + 1)
12
13
+ dp[0] = 0
14
15
+ for coin in coins {
16
+ for index in stride(from: coin, to: dp.count, by: 1) where dp[index - coin] != .max && dp[index - coin] + 1 < dp[index] {
17
+ dp[index] = dp[index - coin] + 1
18
+ }
19
20
21
+ return dp.last == .max ? -1 : dp.last!
22
23
+}
0 commit comments