Участник:Turk0v/Ones and Zeroes

Материал из DISCOPAL
Перейти к: навигация, поиск
class Solution:
    def findMaxForm(self, strs: List[str], m: int, n: int) -> int:
        res_list = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
        for tmp_str in strs:
            a1 = 0
            b1 = 0
            for s in tmp_str:
                if s == "0":
                    a1 += 1
                else:
                    b1 += 1
            for i in range(m, a1 - 1, -1):
                for j in range(n, b1 - 1, -1):
                    res_list[i][j] = max(res_list[i][j], res_list[i - a1][j - b1] + 1)
        return res_list[-1][-1]