Java || Matrix || 0ms || beats 100% || T.C - O(m*n) S.C - O(m*n)
\n\n\t// O(mn) O(mn)\n\tpublic int[][] matrixReshape(int[][] mat, int r, int c) {\n\n\t\tint m = mat.length, n = mat[0].length;\n\t\tif (m * n != r * c)\n\t\t\t
\n\n\t// O(m*n) O(m*n)\n\tpublic int[][] matrixReshape(int[][] mat, int r, int c) {\n\n\t\tint m = mat.length, n = mat[0].length;\n\t\tif (m * n != r * c)\n\t\t\treturn mat;\n\n\t\tint[][] ans = new int[r][c];\n\t\tint x = 0, y = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tans[x][y] = mat[i][j];\n\t\t\t\ty++;\n\t\t\t\tif (y == c) {\n\t\t\t\t\tx++;\n\t\t\t\t\ty = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}
[]