1def reorderList(head):2    fast, slow = head, head3    while fast and fast.next:4        fast = fast.next.next5        slow = slow.next6    second = slow.next7    slow.next, prev = None, None8    while second:9        temp = second.next10        second.next = prev11        prev = second12        second = temp13    second = prev14    first = head15    while second:16        tf = first.next17        ts = second.next18        first.next = second19        second.next = tf20        first = tf21        second = ts