@@ -0,0 +1,1795 @@
+# Time:  O(m * n)%0A# Space: O(m * n)%0A%0A# In MATLAB, there is a very useful function called 'reshape',%0A# which can reshape a matrix into a new one with different size but keep its original data.%0A#%0A# You're given a matrix represented by a two-dimensional array,%0A# and two positive integers r and c representing the row number%0A# and column number of the wanted reshaped matrix, respectively.%0A#%0A# The reshaped matrix need to be filled with%0A# all the elements of the original matrix in the same row-traversing order as they were.%0A#%0A# If the 'reshape' operation with given parameters is possible and legal,%0A# output the new reshaped matrix; Otherwise, output the original matrix.%0A#%0A# Example 1:%0A# Input: %0A# nums = %0A# %5B%5B1,2%5D,%0A#  %5B3,4%5D%5D%0A# r = 1, c = 4%0A# Output: %0A# %5B%5B1,2,3,4%5D%5D%0A# Explanation:%0A# The row-traversing of nums is %5B1,2,3,4%5D. The new reshaped matrix is a 1 * 4 matrix,%0A# fill it row by row by using the previous list.%0A#%0A# Example 2:%0A# Input: %0A# nums = %0A# %5B%5B1,2%5D,%0A#  %5B3,4%5D%5D%0A# r = 2, c = 4%0A# Output: %0A# %5B%5B1,2%5D,%0A#  %5B3,4%5D%5D%0A# Explanation:%0A# There is no way to reshape a 2 * 2 matrix to a 2 * 4 matrix. So output the original matrix.%0A#%0A# Note:%0A# The height and width of the given matrix is in range %5B1, 100%5D.%0A# The given r and c are all positive.%0A%0Aclass Solution(object):%0A    def matrixReshape(self, nums, r, c):%0A        %22%22%22%0A        :type nums: List%5BList%5Bint%5D%5D%0A        :type r: int%0A        :type c: int%0A        :rtype: List%5BList%5Bint%5D%5D%0A        %22%22%22%0A        if not nums or %5C%0A           r*c != len(nums) * len(nums%5B0%5D):%0A            return nums%0A%0A        result = %5B%5B0 for _ in xrange(c)%5D for _ in xrange(r)%5D%0A        count = 0%0A        for i in xrange(len(nums)):%0A            for j in xrange(len(nums%5B0%5D)):%0A                result%5Bcount/c%5D%5Bcount%25c%5D = nums%5Bi%5D%5Bj%5D%0A                count += 1%0A        return result%0A

Create reshape-the-matrix.py