We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5154e4d commit 2f8fc22Copy full SHA for 2f8fc22
Medium/Combination Sum IV.java
@@ -0,0 +1,25 @@
1
+class Solution {
2
+ public int combinationSum4(int[] nums, int target) {
3
+ Integer[] dp = new Integer[target + 1];
4
+ return getCount(target, nums, dp);
5
+ }
6
+
7
+ public int getCount(int target, int[] nums, Integer[] dp) {
8
+ if (dp[target] != null) {
9
+ return dp[target];
10
11
+ if (target == 0) {
12
+ return 1;
13
14
+ if (target < 0) {
15
+ return 0;
16
17
+ int total = 0;
18
+ for (int num : nums) {
19
+ if (target >= num) {
20
+ total += getCount(target - num, nums, dp);
21
22
23
+ return dp[target] = total;
24
25
+}
0 commit comments