diff --git a/problems/0416.分割等和子集.md b/problems/0416.分割等和子集.md index 81eb4c80..71e01ae3 100644 --- a/problems/0416.分割等和子集.md +++ b/problems/0416.分割等和子集.md @@ -726,7 +726,35 @@ object Solution { } } ``` +### C# +```csharp +public class Solution +{ + public bool CanPartition(int[] nums) + { + int sum = 0; + int[] dp = new int[10001]; + foreach (int num in nums) + { + sum += num; + } + if (sum % 2 == 1) return false; + int tartget = sum / 2; + for (int i = 0; i < nums.Length; i++) + { + for (int j = tartget; j >= nums[i]; j--) + { + dp[j] = Math.Max(dp[j], dp[j - nums[i]] + nums[i]); + } + } + if (dp[tartget] == tartget) + return true; + return false; + + } +} +```