Python, Simple with Explanation
Collect the values of the array A, and then put them into the answer of size nR x nC.\n\n\ndef matrixReshape(self, A, nR, nC):\n    if len(A) * len(A[0]) != nR 
Collect the values of the array A, and then put them into the answer of size ```nR x nC```.\n\n```\ndef matrixReshape(self, A, nR, nC):\n    if len(A) * len(A[0]) != nR * nC:\n        return A\n        \n    vals = (val for row in A for val in row)\n    return [[vals.next() for c in xrange(nC)] for r in xrange(nR)]\n```\n\nAlternative solution without generators:\n```\ndef matrixReshape(self, A, nR, nC):\n    if len(A) * len(A[0]) != nR * nC:\n        return A\n        \n    vals = [val for row in A for val in row]\n    ans = [[None] * nC for _ in xrange(nR)]\n    i = 0\n    for r in xrange(nR):\n        for c in xrange(nC):\n            ans[r][c] = vals[i]\n            i += 1\n    return ans
[]