File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,414 LeetCode solutions in JavaScript
1
+ # 1,415 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1239
1239
1601|[ Maximum Number of Achievable Transfer Requests] ( ./solutions/1601-maximum-number-of-achievable-transfer-requests.js ) |Hard|
1240
1240
1603|[ Design Parking System] ( ./solutions/1603-design-parking-system.js ) |Easy|
1241
1241
1604|[ Alert Using Same Key-Card Three or More Times in a One Hour Period] ( ./solutions/1604-alert-using-same-key-card-three-or-more-times-in-a-one-hour-period.js ) |Medium|
1242
+ 1605|[ Find Valid Matrix Given Row and Column Sums] ( ./solutions/1605-find-valid-matrix-given-row-and-column-sums.js ) |Medium|
1242
1243
1657|[ Determine if Two Strings Are Close] ( ./solutions/1657-determine-if-two-strings-are-close.js ) |Medium|
1243
1244
1668|[ Maximum Repeating Substring] ( ./solutions/1668-maximum-repeating-substring.js ) |Easy|
1244
1245
1669|[ Merge In Between Linked Lists] ( ./solutions/1669-merge-in-between-linked-lists.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1605. Find Valid Matrix Given Row and Column Sums
3
+ * https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum
7
+ * of the elements in the ith row and colSum[j] is the sum of the elements of the jth column of a
8
+ * 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums
9
+ * of each row and column.
10
+ *
11
+ * Find any matrix of non-negative integers of size rowSum.length x colSum.length that satisfies
12
+ * the rowSum and colSum requirements.
13
+ *
14
+ * Return a 2D array representing any matrix that fulfills the requirements. It's guaranteed that
15
+ * at least one matrix that fulfills the requirements exists.
16
+ */
17
+
18
+ /**
19
+ * @param {number[] } rowSum
20
+ * @param {number[] } colSum
21
+ * @return {number[][] }
22
+ */
23
+ var restoreMatrix = function ( rowSum , colSum ) {
24
+ const rows = rowSum . length ;
25
+ const cols = colSum . length ;
26
+ const matrix = Array . from ( { length : rows } , ( ) => Array ( cols ) . fill ( 0 ) ) ;
27
+
28
+ for ( let i = 0 ; i < rows ; i ++ ) {
29
+ for ( let j = 0 ; j < cols ; j ++ ) {
30
+ const value = Math . min ( rowSum [ i ] , colSum [ j ] ) ;
31
+ matrix [ i ] [ j ] = value ;
32
+ rowSum [ i ] -= value ;
33
+ colSum [ j ] -= value ;
34
+ }
35
+ }
36
+
37
+ return matrix ;
38
+ } ;
You can’t perform that action at this time.
0 commit comments