File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,691 LeetCode solutions in JavaScript
1
+ # 1,692 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1550
1550
2017|[ Grid Game] ( ./solutions/2017-grid-game.js ) |Medium|
1551
1551
2018|[ Check if Word Can Be Placed In Crossword] ( ./solutions/2018-check-if-word-can-be-placed-in-crossword.js ) |Medium|
1552
1552
2019|[ The Score of Students Solving Math Expression] ( ./solutions/2019-the-score-of-students-solving-math-expression.js ) |Hard|
1553
+ 2022|[ Convert 1D Array Into 2D Array] ( ./solutions/2022-convert-1d-array-into-2d-array.js ) |Easy|
1553
1554
2027|[ Minimum Moves to Convert String] ( ./solutions/2027-minimum-moves-to-convert-string.js ) |Easy|
1554
1555
2033|[ Minimum Operations to Make a Uni-Value Grid] ( ./solutions/2033-minimum-operations-to-make-a-uni-value-grid.js ) |Medium|
1555
1556
2037|[ Minimum Number of Moves to Seat Everyone] ( ./solutions/2037-minimum-number-of-moves-to-seat-everyone.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2022. Convert 1D Array Into 2D Array
3
+ * https://leetcode.com/problems/convert-1d-array-into-2d-array/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers,
7
+ * m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n
8
+ * columns using all the elements from original.
9
+ *
10
+ * The elements from indices 0 to n - 1 (inclusive) of original should form the first row
11
+ * of the constructed 2D array, the elements from indices n to 2 * n - 1 (inclusive) should
12
+ * form the second row of the constructed 2D array, and so on.
13
+ *
14
+ * Return an m x n 2D array constructed according to the above procedure, or an empty 2D array
15
+ * if it is impossible.
16
+ */
17
+
18
+ /**
19
+ * @param {number[] } original
20
+ * @param {number } m
21
+ * @param {number } n
22
+ * @return {number[][] }
23
+ */
24
+ var construct2DArray = function ( original , m , n ) {
25
+ if ( original . length !== m * n ) return [ ] ;
26
+
27
+ const result = [ ] ;
28
+ for ( let i = 0 ; i < m ; i ++ ) {
29
+ result . push ( original . slice ( i * n , ( i + 1 ) * n ) ) ;
30
+ }
31
+
32
+ return result ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments