leetcode 160 相交链表

ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        if( headA== nullptr || headB== nullptr )
            return nullptr;
        ListNode* pA= headA;
        ListNode* pB= headB;
        while( pA!= pB ){
            pA = pA== nullptr? headB:headA->next;
            pB = pB== nullptr? headA:headB->next;
        }
        return pA;
    }

 

你可能感兴趣的:(算法,leetcode)