Java Simple Solution (0 ms, faster than 100.00%)
Runtime: 0 ms, faster than 100.00% of Java online submissions.\nMemory Usage: 39.7 MB, less than 90.75% of Java online submissions.\n\nclass Solution {\n    pub
**Runtime: 0 ms, faster than 100.00% of Java online submissions.\nMemory Usage: 39.7 MB, less than 90.75% of Java online submissions.**\n```\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        int[][] ans = new int[r][c];\n        \n        if(r*c != mat.length*mat[0].length)\n            return mat;\n        \n        int row = 0;\n        int col = 0;\n        for(int i=0; i<mat.length; i++){\n            for(int j=0; j<mat[0].length; j++){\n                ans[row][col++] = mat[i][j];\n        \n                if(col == c){\n                    col = 0;\n                    row++;\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']