2026-06-01 18:12:40 +08:00
#+ANKI_DECK : study_deck_02
2026-06-01 17:12:10 +08:00
* TODO 0322. Coin Change :medium:
2026-06-01 02:33:30 +08:00
:PROPERTIES:
2026-06-01 17:22:07 +08:00
:NEETCODE: [[file:../../roadmap.org::*0322. Coin Change][0322. Coin Change]]
2026-06-01 02:33:30 +08:00
:END:
2026-06-01 17:22:07 +08:00
You are given an integer array ~coins~ representing coins of different denominations and an integer ~amount~ representing a total amount of money.
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~ .
You may assume that you have an infinite number of each kind of coin.
*Example 1:*
#+begin_ src
Input: coins = [1,2,5], amount = 11
Output: 3
Explanation: 11 = 5 + 5 + 1
#+end_src
*Example 2:*
#+begin_ src
Input: coins = [2], amount = 3
Output: -1
#+end_src
*Example 3:*
#+begin_ src
Input: coins = [1], amount = 0
Output: 0
#+end_src
*Constraints:*
- ~1 <= coins.length <= 12~
- ~1 <= coins[i] <= 2^{31} - 1~
- ~0 <= amount <= 10^{4}~
2026-06-01 02:39:53 +08:00
** TODO Approach
Write your approach here.
** TODO Python
2026-06-05 22:32:49 +08:00
#+begin_src python :lc-problem 322 :lc-lang python3
2026-06-01 17:22:07 +08:00
class Solution :
def coinChange ( self , coins : List [ int ] , amount : int ) - > int :
2026-06-01 02:39:53 +08:00
#+end_src
** TODO C++
2026-06-05 22:32:49 +08:00
#+begin_src cpp :lc-problem 322
2026-06-01 17:22:07 +08:00
class Solution {
public :
int coinChange ( vector < int > & coins , int amount ) {
}
} ;
2026-06-01 02:33:30 +08:00
#+end_src