Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 623 Bytes

1605.md

File metadata and controls

21 lines (19 loc) · 623 Bytes

1605. Find Valid Matrix Given Row and Column Sums

Solution 1 (time O(mn), space O(mn))

class Solution(object):
    def restoreMatrix(self, rowSum, colSum):
        """
        :type rowSum: List[int]
        :type colSum: List[int]
        :rtype: List[List[int]]
        """
        m, n = len(rowSum), len(colSum)
        ans = [[0 for _ in range(n)] for _ in range(m)]
        for i in range(m):
            for j in range(n):
                ans[i][j] = min(rowSum[i], colSum[j])
                rowSum[i] -= ans[i][j]
                colSum[j] -= ans[i][j]
        return ans