Complete the code to find the middle node of the linked list using slow and fast pointers.
slow = head fast = head while fast and fast.next: slow = slow.[1] fast = fast.next.next
The slow pointer moves one step at a time using next to find the middle node.
Complete the code to reverse the second half of the linked list starting from the middle node.
prev = None current = slow while current: next_node = current.[1] current.next = prev prev = current current = next_node
We store the next node using current.next before reversing the pointer.
Fix the error in merging two halves of the linked list alternately.
first = head second = prev while second: temp1 = first.next temp2 = second.next first.next = second second.next = [1] first = temp1 second = temp2
After linking second node, we link it to the next node of the first half, which is temp1.
Fill both blanks to complete the function that reorders the linked list.
def reorderList(head): if not head or not head.next: return slow = head fast = head while fast and fast.next: slow = slow.[1] fast = fast.next.next prev = None current = slow.[2] slow.next = None
Both blanks use next to move forward in the list.
Fill all three blanks to merge the two halves of the list correctly.
first = head second = prev while second: temp1 = first.next temp2 = second.next first.next = second second.next = [1] first = [2] second = [3]
We link second.next to temp1, then move first and second pointers to temp1 and temp2 respectively.