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 94bbd8b commit fd85721Copy full SHA for fd85721
java/0377-combination-sum-iv.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int combinationSum4(int[] nums, int target) {
3
+ Map<Integer, Integer> cache = new HashMap<>();
4
+
5
+ cache.put(0, 1);
6
7
+ for (int i = 1; i < target + 1; i++) {
8
+ cache.put(i, 0);
9
+ for (int n : nums) {
10
+ int temp = cache.containsKey(i - n) ? cache.get(i - n) : 0;
11
+ cache.put(i, cache.get(i) + temp);
12
+ }
13
14
15
+ return cache.get(target);
16
17
+}
0 commit comments