LC 160. Intersection of Two Linked Lists

Nilanjan Deb · April 5, 2020

This is my CPP solution.

class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        ListNode* f = headA;
        while(f!=NULL){
            ListNode* s = headB;
            while(s!=NULL){
                if(f==s)
                    return s;
                s = s->next;
            }
            f = f->next;
        }
        return NULL;
    }
};


Dicussion Forum