mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
Update 0474.一和零,添加C#
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user