Easy Solution Java in Single for loop:
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(r*c)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(r*c)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[][] matrixReshape(int[][] mat, int r, int c) {\n        if(mat.length * mat[0].length != r*c){\n            return mat;\n        }\n      \n        int rshape[][] = new int [r][c];\n        \n         for (int i = 0;\n             i < c*r; i++) {\n \n\n            int row1 = i / mat[0].length;\n            int col1 = i % mat[0].length;\n            int row2 = i / c;\n            int col2 = i % c;\n\n            rshape[row2][col2] = mat[row1][col1];\n            \n        }\n       \n        return rshape;\n    }\n}\n```
['Java']