Update 0474.一和零,添加C#

This commit is contained in:
eeee0717
2024-01-20 09:51:00 +08:00
parent e0b0078eea
commit fddab1a7f4

View File

@ -533,6 +533,33 @@ impl Solution {
}
}
```
### C#
```csharp
public class Solution
{
public int FindMaxForm(string[] strs, int m, int n)
{
int[,] dp = new int[m + 1, n + 1];
foreach (string str in strs)
{
int zero = 0, one = 0;
foreach (char c in str)
{
if (c == '0') zero++;
else one++;
}
for (int i = m; i >= zero; i--)
{
for (int j = n; j >= one; j--)
{
dp[i, j] = Math.Max(dp[i, j], dp[i - zero, j - one] + 1);
}
}
}
return dp[m, n];
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">