✅📌 Best Solution || 100%(0ms) || Clean Code
\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        int[][] matrix = new int[r][c];\n        if(r*c != mat.length*mat[0].
```\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        int[][] matrix = new int[r][c];\n        if(r*c != mat.length*mat[0].length) return mat;\n        int m = 0;\n        int n = 0;\n        for(int i=0;i<mat.length;i++){\n            for(int j=0;j<mat[0].length;j++){\n                if(m!=r){\n                    matrix[m][n]=mat[i][j];\n                    n++;\n                    if(n==c){\n                       m++;\n                       n=0;\n                    }\n                }\n            }\n        }\n        return matrix;\n    }\n}\n```\n**Feel free to ask questions in the comment section.**
['Java']