Skip to content

Commit 590f5ee

Browse files
authored
Update 1605-find-valid-matrix-given-row-and-column-sums.js
1 parent c36c73d commit 590f5ee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

1605-find-valid-matrix-given-row-and-column-sums.js

+20
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,23 @@ const restoreMatrix = function(rowSum, colSum) {
1515
}
1616
return res;
1717
};
18+
19+
// another
20+
21+
/**
22+
* @param {number[]} rowSum
23+
* @param {number[]} colSum
24+
* @return {number[][]}
25+
*/
26+
const restoreMatrix = function(rowSum, colSum) {
27+
const m = rowSum.length, n = colSum.length
28+
const res = Array.from({ length: m }, () => Array(n).fill(0))
29+
for(let i = 0; i < m; i++) {
30+
for(let j = 0; j < n; j++) {
31+
res[i][j] = Math.min(rowSum[i], colSum[j])
32+
rowSum[i] -= res[i][j]
33+
colSum[j] -= res[i][j]
34+
}
35+
}
36+
return res
37+
};

0 commit comments

Comments
 (0)