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 e7edab1 commit 761312eCopy full SHA for 761312e
โcoin-change/yyyyyyyyyKim.pyโ
@@ -0,0 +1,20 @@
1
+class Solution:
2
+ def coinChange(self, coins: List[int], amount: int) -> int:
3
+
4
+ # DP
5
+ dp = [10001]*(amount+1)
6
+ dp[0] = 0
7
8
+ # 1๋ถํฐ amount๊น์ง ๋ง๋ค ์ ์๋ ์ต์ ๋์ ์ ์๋ฅผ dp์ ์ ๋ฐ์ดํธ
9
+ for i in range(1, amount+1):
10
+ for j in coins:
11
+ # dp[i-j]+1 : (i-j)์์ ๋ง๋๋ ์ต์ ๋์ ์ + ํ์ฌ๋์ (j) 1๊ฐ ์ฌ์ฉ
12
+ # ํ์ฌ๊ธ์ก(i)๋ฅผ ๋ง๋ค ์ ์๋ ์ต์ ๋์ ์ ์ ๋ฐ์ดํธ
13
+ if i - j >= 0:
14
+ dp[i] = min(dp[i], dp[i-j]+1)
15
16
+ # ์ ๋ฐ์ดํธ๋ ๊ฐ์ด ์์ผ๋ฉด -1 ๋ฆฌํด
17
+ if dp[amount] == 10001:
18
+ return -1
19
+ else:
20
+ return dp[amount]
0 commit comments