Easy Python Solution | Faster than 99.3% (76 ms) | With Comments
Easy Python Solution | Faster than 99.3% (76 ms) | With Comments\nRuntime: 76 ms, faster than 99.30% of Python3 online submissions for Reshape the Matrix.\nMemo
# Easy Python Solution | Faster than 99.3% (76 ms) | With Comments\n**Runtime: 76 ms, faster than 99.30% of Python3 online submissions for Reshape the Matrix.\nMemory Usage: 15 MB**\n```\nclass Solution:\n    def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n        rw = len(mat)\n        cl = len(mat[0])\n        old = rw * cl\n        new = r * c\n\t\t\n\t\t# checking if number of elements remains the same\n        if old != new:\n            return mat\n\n        old = [ i for e in mat for i in e]\n        new = []\n\n        a = 0\n        for i in range(r):\n            temp = []\n            for j in range(c):\n                temp.append(old[a])\n                a += 1\n            new.append(temp)\n\n        return new\n```\n
['Python', 'Python3']