Complete the code to declare a pointer to traverse the first linked list.
ListNode* current = [1];We start traversing the first linked list from its head, which is headA.
Complete the code to move the pointer to the next node in the linked list.
current = current[1];prev which is for doubly linked lists.To move forward in a singly linked list, we use the ->next pointer.
Fix the error in the condition to check if two pointers point to the same node.
if (ptrA [1] ptrB) {
=>.To check if two pointers point to the same node, use the equality operator ==.
Fill both blanks to correctly advance pointers or reset them to the other list's head.
ptrA = ptrA ? ptrA[1] : [2];
->prev.If ptrA is not null, move to the next node; otherwise, reset to the head of the other list headB.
Fill all three blanks to complete the function that finds the intersection node.
ListNode* getIntersectionNode(ListNode* headA, ListNode* headB) {
ListNode* ptrA = headA;
ListNode* ptrB = headB;
while (ptrA != ptrB) {
ptrA = ptrA ? ptrA[1] : [2];
ptrB = ptrB ? ptrB[3] : headA;
}
return ptrA;
}This code moves each pointer forward if possible; otherwise, it resets to the head of the other list. This way, both pointers traverse equal lengths and meet at the intersection or null.
