java 100% faster solution
\npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n        if(r*c != mat[0].length*mat.length){\n            return mat;\n        }\n        int ans [
```\npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n        if(r*c != mat[0].length*mat.length){\n            return mat;\n        }\n        int ans [][] = new int[r][c];\n        int m =0,n=0;\n        for(int i=0;i<r;i++){\n            for(int j=0;j<c;j++){\n                ans[i][j] = mat[m][n];\n                if(n< mat[0].length-1){\n                    n++;\n                }else{\n                    m++;\n                    n=0; \n                }\n                \n            }\n        }\n        return ans;\n    }\n```\n
['Java']