17 lines
558 B
Python
17 lines
558 B
Python
# https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums
|
|
from typing import List
|
|
|
|
class Solution:
|
|
def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -> List[List[int]]:
|
|
ret: List[List[int]] = []
|
|
i = 0
|
|
while i < len(rowSum):
|
|
ret.append([])
|
|
j = 0
|
|
while j < len(colSum):
|
|
ret[i].append(min(rowSum[i], colSum[j]))
|
|
rowSum[i] -= ret[i][j]
|
|
colSum[j] -= ret[i][j]
|
|
j += 1
|
|
i += 1
|
|
return ret
|