You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite number of each kind of coin.
7
+
8
+
Example 1:
9
+
10
+
Input: amount = 5, coins = [1, 2, 5]
11
+
Output: 4
12
+
Explanation: there are four ways to make up the amount:
13
+
5=5
14
+
5=2+2+1
15
+
5=2+1+1+1
16
+
5=1+1+1+1+1
17
+
Example 2:
18
+
19
+
Input: amount = 3, coins = [2]
20
+
Output: 0
21
+
Explanation: the amount of 3 cannot be made up just with coins of 2.
22
+
Example 3:
23
+
24
+
Input: amount = 10, coins = [10]
25
+
Output: 1
26
+
27
+
Note:
28
+
29
+
You can assume that
30
+
31
+
0 <= amount <= 5000
32
+
1 <= coin <= 5000
33
+
the number of coins is less than 500
34
+
the answer is guaranteed to fit into signed 32-bit integer
0 commit comments