Skip to content

Commit 598b95b

Browse files
authored
Create m322.py
1 parent 31fbc5a commit 598b95b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

my-submissions/m322.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def coinChange(self, coins: List[int], amount: int) -> int:
3+
@cache
4+
def recurs(amount: int) -> int :
5+
if amount == 0 :
6+
return 0
7+
minn = inf
8+
9+
# goes in sorted order
10+
for c in coins :
11+
if amount - c < 0 :
12+
break
13+
minn = min(minn, recurs(amount - c))
14+
if minn == 0 :
15+
break
16+
17+
return minn + 1
18+
19+
coins.sort()
20+
21+
# Is cached so it recalling it isn't a big deal
22+
return recurs(amount) if recurs(amount) != inf else -1

0 commit comments

Comments
 (0)