Accepted C solution (Easy to Understand)


  • 0
    A
     struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
        struct ListNode* current1 = headA;
        struct ListNode* current2 = headB;
        if (current1 == NULL || current2 == NULL){
            return NULL;
        }
        while(current1 != current2){
                if(current1 != NULL){
                    current1 = current1->next;
                }else{
                    current1 = headB;
                }
                if(current2 != NULL){
                    current2 = current2->next;
                }else{
                    current2 = headA;
                }
            }
        
        return current1;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.