Skip to content

Commit 0cf08f5

Browse files
committed
https://leetcode.cn/problems/reshape-the-matrix/
1 parent 2ea9c51 commit 0cf08f5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/reshape-the-matrix/
14+
1315
https://leetcode.cn/problems/sZ59z6/
1416

1517
https://leetcode.cn/problems/LwUNpT/

reshape-the-matrix/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function matrixReshape(
2+
mat: number[][],
3+
r: number,
4+
c: number,
5+
): number[][] {
6+
if (r * c !== mat.length * mat[0].length) return mat;
7+
const arr = mat.flat();
8+
9+
return [...Array(r).keys()].map((i) => arr.slice(i * c, i * c + c));
10+
}

0 commit comments

Comments
 (0)