Skip to content

Commit f70a492

Browse files
authored
Merge pull request #2873 from mdmzfzl/main
Create: 0377-combination-sum-iv.c
2 parents 2ce2584 + 777a9e0 commit f70a492

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

c/0377-combination-sum-iv.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int combinationSum4(int* nums, int numsSize, int target) {
2+
uint64_t dp[target + 1]; // Using uint64_t to avoid overflow
3+
for (int i = 0; i <= target; i++) {
4+
dp[i] = 0;
5+
}
6+
7+
dp[0] = 1;
8+
9+
for (int i = 1; i <= target; i++) {
10+
for (int j = 0; j < numsSize; j++) {
11+
if (i - nums[j] >= 0) {
12+
dp[i] += dp[i - nums[j]];
13+
}
14+
}
15+
}
16+
17+
return (int)dp[target];
18+
}

0 commit comments

Comments
 (0)