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
| 1046 |[Last Stone Weight](/problems/last-stone-weight)| Easy | Heap, Greedy |
113
141
| 1143 |[Longest Common Subsequence](/problems/longest-common-subsequence)| Medium | Dynamic Programming |
114
142
| 1144 |[Decrease Elements To Make Array Zigzag](/problems/decrease-elements-to-make-array-zigzag)| Medium | Array |
@@ -180,7 +208,7 @@ The listing below is sorted based on LeetCode #. If you are interested to see my
180
208
| 1476 |[Subrectangle Queries](/problems/subrectangle-queries)| Medium | Array |
181
209
| 1480 |[Running Sum of 1d Array](/problems/running-sum-of-1d-array)| Easy | Array |
182
210
| 1481 |[Least Number of Unique Integers after K Removals](/problems/least-number-of-unique-integers-after-k-removals)| Medium | Array, Sort |
183
-
| 1491 |[Average Salary Excluding the Minimum and Maximum Salary](/problems/average-salary-excluding-the-minimum-and-maximum-salary)| Easy | Array, Sort.|
211
+
| 1491 |[Average Salary Excluding the Minimum and Maximum Salary](/problems/average-salary-excluding-the-minimum-and-maximum-salary)| Easy | Array, Sort |
184
212
| 1492 |[The kth Factor of n](/problems/the-kth-factor-of-n)| Medium | Math |
185
213
| 1493 |[Longest Subarray of 1's After Deleting One Element](/problems/longest-subarray-of-1s-after-deleting-one-element)| Medium | Array |
There are `n` cities connected by `m` flights. Each flight starts from city `u` and arrives at `v` with a price `w`.
12
+
13
+
Now given all the cities and flights, together with starting city `src` and the destination `dst`, your task is to find the cheapest price from `src` to `dst` with up to `k` stops. If there is no such route, output `-1`.
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.
12
+
13
+
Example 1:
14
+
15
+
```text
16
+
Input: amount = 5, coins = [1, 2, 5]
17
+
Output: 4
18
+
Explanation: there are four ways to make up the amount:
19
+
5=5
20
+
5=2+2+1
21
+
5=2+1+1+1
22
+
5=1+1+1+1+1
23
+
```
24
+
25
+
Example 2:
26
+
27
+
```text
28
+
Input: amount = 3, coins = [2]
29
+
Output: 0
30
+
Explanation: the amount of 3 cannot be made up just with coins of 2.
31
+
```
32
+
33
+
Example 3:
34
+
35
+
```text
36
+
Input: amount = 10, coins = [10]
37
+
Output: 1
38
+
```
39
+
40
+
Note:
41
+
42
+
You can assume that
43
+
44
+
-`0 <= amount <= 5000`
45
+
-`1 <= coin <= 5000`
46
+
- the number of coins is less than 500
47
+
- the answer is guaranteed to fit into signed 32-bit integer
48
+
49
+
## Solution Explanation
50
+
51
+
This is a [knapsack problem](https://en.wikipedia.org/wiki/Knapsack_problem) which can be solved by using dynamic programming.
52
+
53
+
Reference: [Knapsack problem - Java solution with thinking process O(nm) Time and O(m) Space](https://leetcode.com/problems/coin-change-2/discuss/99212/Knapsack-problem-Java-solution-with-thinking-process-O(nm)-Time-and-O(m)-Space) by [tankztc](https://leetcode.com/tankztc)
54
+
55
+
## Complexity Analysis
56
+
57
+
Assume m is the amount and n is the number of coins.
0 commit comments