From 82ba33d18e56174c75ac3ad24500fa0f759433e2 Mon Sep 17 00:00:00 2001 From: ist187644 Date: Sat, 23 Oct 2021 11:21:07 +0100 Subject: [PATCH] Added solution for 322. Coin Change Leetcode problem --- LeetCode/Problems/Python/322_Coin_Change.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 LeetCode/Problems/Python/322_Coin_Change.py diff --git a/LeetCode/Problems/Python/322_Coin_Change.py b/LeetCode/Problems/Python/322_Coin_Change.py new file mode 100644 index 00000000..24436444 --- /dev/null +++ b/LeetCode/Problems/Python/322_Coin_Change.py @@ -0,0 +1,15 @@ +class Solution: + def coinChange(self, coins, amount): + dp = [float('inf')]*(amount+1) + dp[0] = 0 + + for i in range(1, amount+1): + ans = float('inf') + for c in coins: + if(i-c >= 0): + ans = min(ans, dp[i-c] + 1) + dp[i] = ans + + + + return dp[-1] if dp[-1] != float('inf') else -1 # dp[amount+1] \ No newline at end of file