322. Coin Change Medium
1/**
2 * [322] Coin Change
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 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.
6 * You may assume that you have an infinite number of each kind of coin.
7 *
8 * Example 1:
9 *
10 * Input: coins = [1,2,5], amount = 11
11 * Output: 3
12 * Explanation: 11 = 5 + 5 + 1
13 *
14 * Example 2:
15 *
16 * Input: coins = [2], amount = 3
17 * Output: -1
18 *
19 * Example 3:
20 *
21 * Input: coins = [1], amount = 0
22 * Output: 0
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= coins.length <= 12
28 * 1 <= coins[i] <= 2^31 - 1
29 * 0 <= amount <= 10^4
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/coin-change/
35// discuss: https://leetcode.com/problems/coin-change/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn coin_change(coins: Vec<i32>, amount: i32) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_322() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.