From 9eb2bec1b01e0baa9254401c732a6fb86d55df39 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Mon, 22 Jan 2024 10:32:00 +0800 Subject: [PATCH] =?UTF-8?q?Update=200377.=E7=BB=84=E5=90=88=E7=BB=BC?= =?UTF-8?q?=E5=90=884=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0377.组合总和Ⅳ.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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]; + } +} +```