Skip to content

Commit 8ae303a

Browse files
committed
add 566v2
1 parent dbce9a8 commit 8ae303a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

easy/566-reshape-matrix.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@
3131

3232
return ans;
3333
};
34+
35+
const matrixReshape2 = (nums, r, c) => {
36+
const m = nums.length;
37+
const n = nums[0].length;
38+
39+
if (m * n < r * c) {
40+
return nums;
41+
}
42+
43+
const answer = [];
44+
for (let i = 0; i < r * c; i++) {
45+
answer[i/c][i%c] = nums[i/n][i%n];
46+
}
47+
return answer;
48+
};

0 commit comments

Comments
 (0)