Python Code


  • 0
    A
    class Solution(object):
        def matrixReshape(self, nums, r, c):
            a = [item for sublist in nums for item in sublist]
            return zip(*[iter(a)]*c) if r*c == len(a) else nums
    

  • 0

    Wrong result type, you're returning a list of tuples instead of a list of lists.


  • 0
    A

    Submission Details
    56 / 56 test cases passed.
    Status: Accepted
    Runtime: 232 ms
    Submitted: 0 minutes ago


  • 1

    Yes, you get away with it because the judge is buggy. Doesn't make it right, though.


  • 0
    A
    Submission Details
    56 / 56 test cases passed.
    Status: Accepted
    Runtime: 162 ms
    Submitted: 0 minutes ago
    
    class Solution(object):
        def matrixReshape(self, nums, r, c):
            a = [item for sublist in nums for item in sublist]
            return [list(e) for e in zip(*[iter(a)]*c)] if r*c == len(a) else nums
    

Log in to reply
 

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