[Python] One pass - Clean & Concise
Python 3\n\nclass Solution:\n    def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n        m, n = len(mat), len(mat[0])\n      
**Python 3**\n```\nclass Solution:\n    def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n        m, n = len(mat), len(mat[0])\n        if r * c != m * n: return mat  # Invalid size -> return original matrix\n        ans = [[0] * c for _ in range(r)]\n        for i in range(m * n):\n            ans[i // c][i % c] = mat[i // n][i % n]\n        return ans\n```\n**Complexity**\n - Time & Space: `O(M*N)`
[]