Solution
C++ []\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        int row = mat.size();\n        int c
```C++ []\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        int row = mat.size();\n        int col = mat[0].size();\n        if (row * col != r * c) return mat;\n        \n        vector<vector<int>> result;\n        int index = c;\n        for (int i = 0; i < row; i++) {\n            for (int j = 0; j < col; j++) {\n                if (index == c) {\n                    result.push_back({});\n                    index = 0;\n                }\n                result[result.size() - 1].push_back(mat[i][j]);\n                index += 1;\n            }\n        }\n        return result;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n\n        m=len(mat)\n        n=len(mat[0])\n        if m*n != r*c:\n            return mat\n        flat=[]\n        for i in mat:\n            flat.extend(i)\n    \n        output=[]\n        for i in range(r):\n            output.append(flat[i*c:(i+1)*c])\n        return output\n```\n\n```Java []\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```\n
['C++', 'Java', 'Python3']