[Java] Simple Solution in O(mn) time
\n\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        if(r*c != mat.length*mat[0].length) return mat;\n        int[][] re
\n```\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        if(r*c != mat.length*mat[0].length) return mat;\n        int[][] res = new int[r][c];\n        int ri = 0, cj = 0;\n        for(int i=0; i<mat.length; ++i){\n            for(int j=0; j<mat[0].length; ++j){\n                //System.out.println(ri+" "+cj);\n                res[ri][cj++] = mat[i][j];\n                if(cj >= res[0].length){\n                    cj = 0;\n                    ri++;\n                }\n            }\n        }\n        return res;\n    }\n}\n```\nplease leave a like if you found this helpful\nand leave a comment if you have any question\nhappy coding : )
['Java']