Skip to content

Commit fd85721

Browse files
committed
Create 0377-combination-sum-iv
1 parent 94bbd8b commit fd85721

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

java/0377-combination-sum-iv.java

+17
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)