From fddab1a7f4442e7cebf70f118b6157c6dfb3d67e Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Sat, 20 Jan 2024 09:51:00 +0800 Subject: [PATCH] =?UTF-8?q?Update=200474.=E4=B8=80=E5=92=8C=E9=9B=B6?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0474.一和零.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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]; + } +} +```