Python Solution


  • 0
    A
    class Solution(object):
        def matrixReshape(self, nums, r, c):
            """
            :type nums: List[List[int]]
            :type r: int
            :type c: int
            :rtype: List[List[int]]
            """
            nums_flat = sum(nums, [])
            n = len(nums_flat)
            if n == 0 or n != r * c:
                return nums
            else:
                return [nums_flat[i:i+c] for i in range(0, n, c)]
    

    Does number of lines really matter?


Log in to reply
 

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