File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 414
414
515|[ Find Largest Value in Each Tree Row] ( ./0515-find-largest-value-in-each-tree-row.js ) |Medium|
415
415
516|[ Longest Palindromic Subsequence] ( ./0516-longest-palindromic-subsequence.js ) |Medium|
416
416
517|[ Super Washing Machines] ( ./0517-super-washing-machines.js ) |Hard|
417
+ 518|[ Coin Change II] ( ./0518-coin-change-ii.js ) |Medium|
417
418
520|[ Detect Capital] ( ./0520-detect-capital.js ) |Easy|
418
419
521|[ Longest Uncommon Subsequence I] ( ./0521-longest-uncommon-subsequence-i.js ) |Easy|
419
420
530|[ Minimum Absolute Difference in BST] ( ./0530-minimum-absolute-difference-in-bst.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 518. Coin Change II
3
+ * https://leetcode.com/problems/coin-change-ii/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array coins representing coins of different denominations and
7
+ * an integer amount representing a total amount of money.
8
+ *
9
+ * Return the number of combinations that make up that amount. If that amount of money
10
+ * cannot be made up by any combination of the coins, return 0.
11
+ *
12
+ * You may assume that you have an infinite number of each kind of coin.
13
+ *
14
+ * The answer is guaranteed to fit into a signed 32-bit integer.
15
+ */
16
+
17
+ /**
18
+ * @param {number } amount
19
+ * @param {number[] } coins
20
+ * @return {number }
21
+ */
22
+ var change = function ( amount , coins ) {
23
+ const dp = new Array ( amount + 1 ) . fill ( 0 ) ;
24
+ dp [ 0 ] = 1 ;
25
+
26
+ for ( const coin of coins ) {
27
+ for ( let i = coin ; i <= amount ; i ++ ) {
28
+ dp [ i ] += dp [ i - coin ] ;
29
+ }
30
+ }
31
+
32
+ return dp [ amount ] ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments