Skip to content

Commit b32dac2

Browse files
authored
Create 1605-find-valid-matrix-given-row-and-column-sums.js
1 parent e8d0f46 commit b32dac2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} rowSum
3+
* @param {number[]} colSum
4+
* @return {number[][]}
5+
*/
6+
const restoreMatrix = function(rowSum, colSum) {
7+
const m = rowSum.length, n = colSum.length;
8+
const res = Array.from({ length: m }, () => Array(n).fill(0));
9+
for (let i = 0; i < m; ++i) {
10+
for (let j = 0 ; j < n; ++j) {
11+
res[i][j] = Math.min(rowSum[i], colSum[j]);
12+
rowSum[i] -= res[i][j];
13+
colSum[j] -= res[i][j];
14+
}
15+
}
16+
return res;
17+
};

0 commit comments

Comments
 (0)