My python3 solution


  • 0
    Y
    class Solution(object):
        def matrixReshape(self, nums, r, c):
            """
            :type nums: List[List[int]]
            :type r: int
            :type c: int
            :rtype: List[List[int]]
            """
            all_nums = []
            for item in nums:
                all_nums.extend(item)
            all_num_len = len(all_nums)
            if all_num_len != r * c:
                return nums
            res = []
            for row_num in range(r):
                cur = all_nums[row_num*c:row_num*c+c]
                print(cur)
                res.append(cur)
            return res
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.