This commit is contained in:
parent
6669e03a5e
commit
e46461e1e1
1 changed files with 17 additions and 0 deletions
17
medium/find_valid_matrix_given_row_and_column_sums.py
Normal file
17
medium/find_valid_matrix_given_row_and_column_sums.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue