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 a18a616 commit 9e3a817Copy full SHA for 9e3a817
โcoin-change/YeomChaeeun.ts
@@ -0,0 +1,20 @@
1
+/**
2
+ * ๋์ ๋ค๋ก ๊ธ์ก์ ๋ง๋ค๋ ํ์ํ ์ต์ ๋์ ์ ๊ฐ์ ์ฐพ๊ธฐ
3
+ * ์๊ณ ๋ฆฌ์ฆ ๋ณต์ก๋
4
+ * - ์๊ฐ ๋ณต์ก๋: O(nxm) ๋์ ์ ๊ฐ์ x ๋ง๋ค์ด์ผํ๋ ๊ธ์ก์ ํฌ๊ธฐ
5
+ * - ๊ณต๊ฐ ๋ณต์ก๋: O(m) ์ฃผ์ด์ง ๊ธ์ก์ ๋น๋กํจ
6
+ * @param coins
7
+ * @param amount
8
+ */
9
+function coinChange(coins: number[], amount: number): number {
10
+ const dp = new Array(amount + 1).fill(amount + 1)
11
+ dp[0] = 0 // 0์์ 0๊ฐ
12
+
13
+ for (const coin of coins) {
14
+ for (let i = coin; i <= amount; i++) {
15
+ dp[i] = Math.min(dp[i], dp[i - coin] + 1)
16
+ }
17
18
19
+ return dp[amount] === amount + 1 ? -1 : dp[amount]
20
+}
0 commit comments