From 546865ce4c18c00589dad748e9f8c7eaa29ede80 Mon Sep 17 00:00:00 2001 From: LiangDazhu <42199191+LiangDazhu@users.noreply.github.com> Date: Sun, 6 Jun 2021 00:44:21 +0800 Subject: [PATCH] =?UTF-8?q?Update=200474.=E4=B8=80=E5=92=8C=E9=9B=B6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added python version code --- problems/0474.一和零.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/problems/0474.一和零.md b/problems/0474.一和零.md index e158ca63..a098b9ef 100644 --- a/problems/0474.一和零.md +++ b/problems/0474.一和零.md @@ -190,7 +190,18 @@ class Solution { ``` Python: - +```python +class Solution: + def findMaxForm(self, strs: List[str], m: int, n: int) -> int: + dp = [[0] * (n + 1) for _ in range(m + 1)] + for str in strs: + oneNum = str.count('1') + zeroNum = str.count('0') + for i in range(m, zeroNum - 1, -1): + for j in range(n, oneNum - 1, -1): + dp[i][j] = max(dp[i][j], dp[i - zeroNum][j - oneNum] + 1) + return dp[m][n] +``` Go: