mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0474.一和零.md
Added python version code
This commit is contained in:
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user