Python Solution (very readable)

  • 0

    A few extra lines but very readable. Can someone help me calculate and/or prove the time and space complexity! Thanks

    def matrix(nums,r,c):
        if r*c != len(nums)*len(nums[0]):
            return nums
            array = [] 
            for i in range(len(nums)):
                for j in range(len(nums[0])):
            #all elements will be added to array
            matrix = []
            while len(array) != 0:
                array = array[c::]
            return matrix
            #elements are spliced into lists and appended to matrix

Log in to reply

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