Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7a3115f

Browse files
Merge pull request #143 from JatinLodhi/master
coin-change-py
2 parents 640e4a9 + 3c1697a commit 7a3115f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎Leetcode/coin_change.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def coinChange(self, coins: List[int], amount: int) -> int:
3+
MAX=float('inf')
4+
dp=[0]+[MAX for i in range(amount)]
5+
for i in range(1,amount+1):
6+
for c in coins:
7+
if i-c>=0:
8+
dp[i]=min(dp[i],dp[i-c])
9+
dp[i]+=1
10+
if dp[-1]==MAX:
11+
return -1
12+
else:
13+
return dp[-1]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /