Find Valid Matrix Given Row and Column Sums LeetCode solution in Python

1
class Solution:
2
def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -> List[List[int]]:
3
matrix = []
4
for row in range(len(rowSum)):
5
data, array = rowSum[row], []
6
for col in range(len(colSum)):
7
if data == 0 or colSum[col] == 0:
8
array.append(0)
9
elif data > colSum[col]:
10
data -= colSum[col]
11
array.append(colSum[col])
12
colSum[col] = 0
13
else:
14
array.append(data)
15
colSum[col] -= data
16
data = 0
17
matrix.append(array)
18

19
return matrix

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0