1
class Solution {
2
public int[][] matrixReshape(int[][] mat, int r, int c) {
3

4
if (r * c != mat.length * mat[0].length) {
5
return mat;
6
}
7

8
int[][] ans = new int[r][c];
9

10
int i = 0;
11
int j = 0;
12

13
for (int k = 0; k < mat.length; k++) {
14
for (int l = 0; l < mat[0].length; l++) {
15
if (j == c) {
16
i++;
17
j = 0;
18
}
19
ans[i][j++] = mat[k][l];
20
}
21
}
22
return ans;
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0