File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 377. Combination Sum IV
3
+ * https://leetcode.com/problems/combination-sum-iv/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an array of distinct integers nums and a target integer target, return the number of
7
+ * possible combinations that add up to target.
8
+ *
9
+ * The test cases are generated so that the answer can fit in a 32-bit integer.
10
+ */
11
+
12
+ /**
13
+ * @param {number[] } nums
14
+ * @param {number } target
15
+ * @return {number }
16
+ */
17
+ var combinationSum4 = function ( nums , target ) {
18
+ const dp = new Array ( target + 1 ) . fill ( 0 ) ;
19
+ dp [ 0 ] = 1 ;
20
+
21
+ for ( let i = 1 ; i <= target ; i ++ ) {
22
+ nums . forEach ( n => dp [ i ] += i >= n ? dp [ i - n ] : 0 ) ;
23
+ }
24
+
25
+ return dp [ target ] ;
26
+ } ;
Original file line number Diff line number Diff line change 296
296
374|[ Guess Number Higher or Lower] ( ./0374-guess-number-higher-or-lower.js ) |Medium|
297
297
375|[ Guess Number Higher or Lower II] ( ./0375-guess-number-higher-or-lower-ii.js ) |Medium|
298
298
376|[ Wiggle Subsequence] ( ./0376-wiggle-subsequence.js ) |Medium|
299
+ 377|[ Combination Sum IV] ( ./0377-combination-sum-iv.js ) |Medium|
299
300
378|[ Kth Smallest Element in a Sorted Matrix] ( ./0378-kth-smallest-element-in-a-sorted-matrix.js ) |Medium|
300
301
380|[ Insert Delete GetRandom O(1)] ( ./0380-insert-delete-getrandom-o1.js ) |Medium|
301
302
383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
You can’t perform that action at this time.
0 commit comments