1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import java.util.Arrays;
/**
* You are given an integer array coins representing coins of different
* denominations and an integer amount representing a total amount of money.
* <p>
* Return the fewest number of coins that you need to make up that amount. If
* that amount of money cannot be made up by any combination of the coins, return -1.
* <p>
* You may assume that you have an infinite number of each kind of coin.
* <p>
* <p>
* Example 1:
* <p>
* <p>
* Input: coins = [1,2,5], amount = 11
* Output: 3
* Explanation: 11 = 5 + 5 + 1
* <p>
* <p>
* Example 2:
* <p>
* <p>
* Input: coins = [2], amount = 3
* Output: -1
* <p>
* <p>
* Example 3:
* <p>
* <p>
* Input: coins = [1], amount = 0
* Output: 0
* <p>
* <p>
* <p>
* Constraints:
* <p>
* <p>
* 1 <= coins.length <= 12
* 1 <= coins[i] <= 2³¹ - 1
* 0 <= amount <= 10⁴
* <p>
* <p>
* Related Topics Array Dynamic Programming Breadth-First Search 👍 18909 👎 449
*/
/*
2024-07-23 11:28:08
Coin Change
Category Difficulty Likes Dislikes
algorithms Medium (43.88%) 18909 449
Tags
dynamic-programming
Companies
Unknown
*/
|