Python simple array method


  • 0

    '''
    class Solution(object):
    def reorderList(self, head):

        if head is None:
            return
        data = []
        node = head
        nodes = []
        while node is not None:
            data.append(node.val)
            nodes.append(node)
            node = node.next
        end_index = int(len(data) / 2)
        end_node = nodes[end_index]
        nodes = nodes[end_index + 1:][::-1]
        node = head
        for i in nodes:
            temp = node.next
            node.next = i
            i.next = temp
            node = temp
        end_node.next = None

Log in to reply
 

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