Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ones-and-zeroes.py 745 Bytes
一键复制 编辑 原始数据 按行查看 历史
Allen Liu 提交于 2018-10-12 01:33 +08:00 . remove sensitive question description
# Time: O(s * m * n), s is the size of the array.
# Space: O(m * n)
class Solution(object):
def findMaxForm(self, strs, m, n):
"""
:type strs: List[str]
:type m: int
:type n: int
:rtype: int
"""
dp = [[0 for _ in xrange(n+1)] for _ in xrange(m+1)]
for s in strs:
zero_count, one_count = 0, 0
for c in s:
if c == '0':
zero_count += 1
elif c == '1':
one_count += 1
for i in reversed(xrange(zero_count, m+1)):
for j in reversed(xrange(one_count, n+1)):
dp[i][j] = max(dp[i][j], dp[i-zero_count][j-one_count]+1)
return dp[m][n]
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助