518. Coin Change II Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [518] Coin Change II
3 *
4 * You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
5 * Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.
6 * You may assume that you have an infinite number of each kind of coin.
7 * The answer is guaranteed to fit into a signed 32-bit integer.
8 *  
9 * Example 1:
10 * 
11 * Input: amount = 5, coins = [1,2,5]
12 * Output: 4
13 * Explanation: there are four ways to make up the amount:
14 * 5=5
15 * 5=2+2+1
16 * 5=2+1+1+1
17 * 5=1+1+1+1+1
18 * 
19 * Example 2:
20 * 
21 * Input: amount = 3, coins = [2]
22 * Output: 0
23 * Explanation: the amount of 3 cannot be made up just with coins of 2.
24 * 
25 * Example 3:
26 * 
27 * Input: amount = 10, coins = [10]
28 * Output: 1
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= coins.length <= 300
34 * 	1 <= coins[i] <= 5000
35 * 	All the values of coins are unique.
36 * 	0 <= amount <= 5000
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/coin-change-ii/
42// discuss: https://leetcode.com/problems/coin-change-ii/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn change(amount: i32, coins: Vec<i32>) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_518() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.