What's wrong with my code? The server keeps looping and does not return


  • 0
    X
    class Solution {
    public:
        ListNode *getReversedList(ListNode *head) {
            ListNode ln(0),*r=&ln;
            for(ListNode *p=head;p!=NULL;) {
                r->next=p;
                p=p->next;
                r->next->next=NULL;
                r=r->next;
            }
            return r->next;
        }
        ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
            ListNode *p=NULL,*pa,*pb;
            headA=getReversedList(headA);
            headB=getReversedList(headB);
            for(pa=headA,pb=headB;pa!=NULL&&pb!=NULL;pa=pa->next,pb=pb->next)
                if(pa==pb) p=pa;
                else break;
            headA=getReversedList(headA);
            headB=getReversedList(headB);
            return p;
        }
    };
    

Log in to reply
 

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