diff --git a/problems/1049.最后一块石头的重量II.md b/problems/1049.最后一块石头的重量II.md index cc661317..4c3c01a0 100644 --- a/problems/1049.最后一块石头的重量II.md +++ b/problems/1049.最后一块石头的重量II.md @@ -472,6 +472,30 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int LastStoneWeightII(int[] stones) + { + int[] dp = new int[15001]; + int sum = 0; + foreach (int stone in stones) + { + sum += stone; + } + int target = sum / 2; + for (int i = 0; i < stones.Length; i++) + { + for (int j = target; j >= stones[i]; j--) + { + dp[j] = Math.Max(dp[j], dp[j - stones[i]] + stones[i]); + } + } + return sum - 2 * dp[target]; + } +} +```