C++ Solution
Code\n\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n        int m = nums.size(), n = nums[0].si
# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n        int m = nums.size(), n = nums[0].size();\n        if(m * n != r * c) return nums;\n        vector<vector<int>> ans(r, vector<int>(c));\n        int row = 0, col = 0;\n        for(int i = 0; i < r; i++) {\n            for(int j = 0; j < c; j++) {\n                ans[i][j] = nums[row][col++];\n                if(col == n) col = 0, row++;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']