Java Solution, 0 ms, Beats 100%
Java Code\n\nclass Solution {\n    public int[][] matrixReshape(int[][] nums, int r, int c) {\n        int n = nums.length, m = nums[0].length;\n        if (r *
# Java Code\n```\nclass Solution {\n    public int[][] matrixReshape(int[][] nums, int r, int c) {\n        int n = nums.length, m = nums[0].length;\n        if (r * c != n * m) return nums;\n        int[][] res = new int[r][c];\n        for (int i = 0; i < r * c; i++)\n            res[i / c][i % c] = nums[i / m][i % m];\n        return res;\n    }\n}\n```
['Array', 'Matrix', 'Simulation', 'Java']