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 064e582

Browse files
committed
Update 0416.分割等和子集,添加C#
1 parent 57025dc commit 064e582

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎problems/0416.分割等和子集.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,35 @@ object Solution {
726726
}
727727
}
728728
```
729+
### C#
730+
```csharp
731+
public class Solution
732+
{
733+
public bool CanPartition(int[] nums)
734+
{
735+
int sum = 0;
736+
int[] dp = new int[10001];
737+
foreach (int num in nums)
738+
{
739+
sum += num;
740+
}
741+
if (sum % 2 == 1) return false;
742+
int tartget = sum / 2;
743+
for (int i = 0; i < nums.Length; i++)
744+
{
745+
for (int j = tartget; j >= nums[i]; j--)
746+
{
747+
dp[j] = Math.Max(dp[j], dp[j - nums[i]] + nums[i]);
748+
}
749+
}
750+
if (dp[tartget] == tartget)
751+
return true;
752+
753+
return false;
729754

755+
}
756+
}
757+
```
730758
<p align="center">
731759
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
732760
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>

0 commit comments

Comments
(0)

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