Участник:Turk0v/Reconstruct a 2-Row Binary Matrix

Материал из DISCOPAL
Перейти к: навигация, поиск
class Solution:
    def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]:
        res = list()
        res.append(list())
        res.append(list())
        for i in range(len(colsum)):
            if colsum[i] == 2:
                res[0].append(1)
                res[1].append(1)
                lower -= 1
                upper -= 1
            elif colsum[i] == 0:
                res[0].append(0)
                res[1].append(0)
            else:
                if upper >= lower:
                    res[0].append(1)
                    res[1].append(0)
                    upper -= 1
                else:
                    res[0].append(0)
                    res[1].append(1)
                    lower -= 1
            if upper == -1 or lower == -1:
                return list()
        if upper == 0 and lower == 0:
            return res
        else:
            return list()