Simple Java Solution with 100% Faster
\n\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        if(mat.length * mat[0].length != r*c){\n            return mat;\n  
\n```\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        if(mat.length * mat[0].length != r*c){\n            return mat;\n        }\n        int[][] newMatrix= new int[r][c];\n        int sr = 0;\n        int sc = 0;\n\n        for(int i=0;i<mat.length;i++){\n            for(int j=0 ; j<mat[0].length;j++){\n                if(sc==c){\n                    sr++;\n                    sc=0;\n                }\n                newMatrix[sr][sc] = mat[i][j];\n                sc++;\n            }\n        }\n        return newMatrix;\n    }\n}\n```
['Java']