Skip to content

Commit 9da952d

Browse files
committed
[main] Added mincoins problem
1 parent 31cefcd commit 9da952d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pythonProblems/dp/mincoins.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
4+
def min_coins(n: int, coins: List[int]):
5+
dp = [0] * n
6+
for i in range(n): # iterate through all the potential targets 0...n
7+
for j in range(len(coins)):
8+
dp[i] = min(dp[i], dp[i - j]) + 1
9+
return min(dp)
10+
11+
12+
if __name__ == '__main__':
13+
coins = [1, 5, 7]
14+
target = 11
15+
print(min_coins(target, coins))

0 commit comments

Comments
 (0)