Update 1049.最后一块石头的重量2,添加C#

This commit is contained in:
eeee0717
2024-01-18 10:28:55 +08:00
parent 064e582b1e
commit 49e386d20b

View File

@ -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];
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">