diff --git a/problems/0474.一和零.md b/problems/0474.一和零.md index 8f6197ac..904d941e 100644 --- a/problems/0474.一和零.md +++ b/problems/0474.一和零.md @@ -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]; + } +} +```