diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md index 05f852b1..a840ec9b 100644 --- a/problems/0377.组合总和Ⅳ.md +++ b/problems/0377.组合总和Ⅳ.md @@ -312,6 +312,28 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int CombinationSum4(int[] nums, int target) + { + int[] dp = new int[target + 1]; + dp[0] = 1; + for (int i = 0; i <= target; i++) + { + for (int j = 0; j < nums.Length; j++) + { + if (i >= nums[j] && dp[i] < int.MaxValue - dp[i - nums[j]]) + { + dp[i] += dp[i - nums[j]]; + } + } + } + return dp[target]; + } +} +```