Files

67 lines
1.2 KiB
Org Mode
Raw Permalink Normal View History

2026-06-01 18:12:40 +08:00
#+ANKI_DECK: study_deck_02
* TODO 0322. Coin Change :medium:
:PROPERTIES:
:NEETCODE: [[file:../../roadmap.org::*0322. Coin Change][0322. Coin Change]]
:END:
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}~
** 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
class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
#+end_src
** TODO C++
2026-06-05 22:32:49 +08:00
#+begin_src cpp :lc-problem 322
class Solution {
public:
int coinChange(vector<int>& coins, int amount) {
}
};
#+end_src