Skip to content

Commit 9326628

Browse files
committed
377
1 parent 2dcd72a commit 9326628

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

377/Solution.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int combinationSum4(int[] nums, int target) {
3+
Map<Integer, Integer> map = new HashMap<>();
4+
map.put(0, 1);
5+
for (int i = 0; i <= target; i++) {
6+
int sum = 0;
7+
for (int n : nums) {
8+
sum += map.getOrDefault(i - n, 0);
9+
}
10+
if (sum != 0) {
11+
map.put(i, sum);
12+
}
13+
}
14+
return map.getOrDefault(target, 0);
15+
}
16+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@
133133
- [312 Burst Balloons](./312)
134134
- [337 House Robber III](./337)
135135
- [341 Flatten Nested List Iterator](./341)
136+
- [347 Top K Frequent Elements](./347)
136137
- [349 Intersection of Two Arrays](./349)
137138
- [350 Intersection of Two Arrays II](./350)
139+
- [377 Combination Sum IV](./377)
138140
- [393 UTF-8 Validation](./393)
139141
- [398 Random Pick Index](./398)
140-
- [347 Top K Frequent Elements](./347)
141142
- [414 Third Maximum Number](./414)
142143
- [415 Add Strings](./415)
143144
- [442 Find All Duplicates in an Array](./442)

0 commit comments

Comments
 (0)