Complete the code to move the pointer to the next node in the linked list.
current = current[1];The next property points to the next node in the linked list.
Complete the code to check if two nodes are the same (intersection point).
if (pointerA[1] pointerB) { return pointerA; }
We check if the two pointers point to the exact same node using ==.
Fix the error in the loop condition to continue until both pointers are null.
while (pointerA != null [1] pointerB != null) { /* loop body */ }
We want to continue the loop while either pointer is not null, so we use the logical OR operator ||.
Fill both blanks to advance pointers correctly when they reach the end of their lists.
pointerA = pointerA == null ? [1] : pointerA.next; pointerB = pointerB == null ? [2] : pointerB.next;
When pointerA reaches the end, it starts at headB; when pointerB reaches the end, it starts at headA. This helps find the intersection.
Fill all three blanks to complete the method that finds the intersection node.
public ListNode GetIntersectionNode(ListNode headA, ListNode headB) {
ListNode pointerA = headA;
ListNode pointerB = headB;
while (pointerA != pointerB) {
pointerA = pointerA == null ? [1] : pointerA.next;
pointerB = pointerB == null ? [2] : pointerB.next;
}
return [3];
}PointerA switches to headB, pointerB switches to headA, and the method returns pointerA which is the intersection or null.
