From e46461e1e10add2101837aff58b2fbdc1237eea0 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Sat, 20 Jul 2024 23:01:59 +0900 Subject: [PATCH] https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums --- ...nd_valid_matrix_given_row_and_column_sums.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 medium/find_valid_matrix_given_row_and_column_sums.py diff --git a/medium/find_valid_matrix_given_row_and_column_sums.py b/medium/find_valid_matrix_given_row_and_column_sums.py new file mode 100644 index 0000000..0fadd45 --- /dev/null +++ b/medium/find_valid_matrix_given_row_and_column_sums.py @@ -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