Update 0343.整数拆分,添加C#

This commit is contained in:
eeee0717
2024-01-15 09:52:08 +08:00
parent 08617fdff7
commit 0076152aec

View File

@ -496,6 +496,25 @@ class Solution {
} }
} }
``` ```
### C#
```csharp
public class Solution
{
public int IntegerBreak(int n)
{
int[] dp = new int[n + 1];
dp[2] = 1;
for (int i = 3; i <= n; i++)
{
for (int j = 1; j <= i / 2; j++)
{
dp[i] = Math.Max(dp[i],Math.Max(j*(i-j),j*dp[i-j]));
}
}
return dp[n];
}
}
```
<p align="center"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">