Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 49e386d

Browse files
committed
Update 1049.最后一块石头的重量2,添加C#
1 parent 064e582 commit 49e386d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎problems/1049.最后一块石头的重量II.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,30 @@ impl Solution {
472472
}
473473
}
474474
```
475+
### C#
476+
```csharp
477+
public class Solution
478+
{
479+
public int LastStoneWeightII(int[] stones)
480+
{
481+
int[] dp = new int[15001];
482+
int sum = 0;
483+
foreach (int stone in stones)
484+
{
485+
sum += stone;
486+
}
487+
int target = sum / 2;
488+
for (int i = 0; i < stones.Length; i++)
489+
{
490+
for (int j = target; j >= stones[i]; j--)
491+
{
492+
dp[j] = Math.Max(dp[j], dp[j - stones[i]] + stones[i]);
493+
}
494+
}
495+
return sum - 2 * dp[target];
496+
}
497+
}
498+
```
475499

476500
<p align="center">
477501
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /