File tree Expand file tree Collapse file tree 1 file changed +34
-4
lines changed
Expand file tree Collapse file tree 1 file changed +34
-4
lines changed Original file line number Diff line number Diff line change 11"""
22[๋ฌธ์ ํ์ด]
33# Inputs
4-
4+ - ์ ์ ๋ฐฐ์ด coins
5+ - ์ด ๋์ ๊ฐ amount
56# Outputs
6-
7+ - amount ๋ฅผ ์ฑ์ธ ์ ์๋ ๋์ ์ ๊ฐ์ฅ ์ ์ ์
8+ - ๋ง์ฝ ๋ง๋ค ์ ์๋ค๋ฉด -1 return
79# Constraints
8-
10+ - 1 <= coins.length <= 12
11+ - 1 <= coins[i] <= 2^31 - 1
12+ - 0 <= amount <= 10^4
913# Ideas
14+ - ์ฐ์ ์ด์ ํ์ด ๋ณธ ๊ฑฐ ์ฐ์ตํด๋ณด๊ธฐ
15+ - DP ํ๋ค์ด ๋ฐฉ์์ผ๋ก! ์ด ๋ฌธ์ ํ์ด๋ฅผ ๋ด๊ฐ 100% ์ดํดํ๊ณ ์๋๊ฒ ๋ง๋์ง ์์ผ๋ก ๋์ํ ํด๋ณด๊ธฐ๋กํจ
1016
11- [ํ๊ณ ]
1217
18+ [ํ๊ณ ]
19+ ์ฌ๊ท๋ dp๋ ๋ค์ํ ์ ํ์ ๋ง์ด ํ์ด๋ณด๋ ์ ๋ฐ์..
1320"""
1421
1522
23+ class Solution :
24+ def coinChange (self , coins : List [int ], amount : int ) -> int :
25+ memo = {}
26+
27+ def dp (amount ):
28+
29+ if amount == 0 :
30+ return 0
31+
32+ retList = []
33+ for coin in coins :
34+ if amount - coin >= 0 :
35+ if amount - coin not in memo :
36+ memo [amount - coin ] = dp (amount - coin )
37+
38+ if memo [amount - coin ] != - 1 :
39+ retList .append (memo [amount - coin ])
40+
41+ return min (retList ) + 1 if retList else - 1
42+
43+ return dp (amount )
44+
45+
You canโt perform that action at this time.
0 commit comments