I get a problem,talk about my opinion


  • 0
    S
    my code is like:
    

    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB)
    {
    if (!headA || !headB)return NULL;
    headA = fanzhuan(headA);
    headB = fanzhuan(headB);
    ListNode *p = headA, *q = headB;
    while (p&&p->val == q->val)
    {
    p = p->next;
    q = q->next;
    }
    headA = fanzhuan(headA);
    headB = fanzhuan(headB);

    if (p == NULL)
    	return headA;
    return p->next;
    }
    ListNode * fanzhuan(ListNode *head)
    {
        ListNode *newhead=NULL, *p,*q;
        while(head)
        {
            p=newhead;
            newhead=head;
            head=head->next;
            newhead->next=p;
        }
        return newhead;
    }
    

    and the result is:
    Input: Intersected at '1': [1,2,3,4,5,6,7,8,9,10,11,12,13] [1,2,3,4,5,6,7,8,9,10,11,12,13]
    Output: Intersected at '12', ERROR: linked structure was modified.
    Expected: Intersected at '1'

    i think the linked lists they gived may be in the same place,it is just two point like :
    ListNode *p=XXX,*q=p;

    right?

    please tell me


Log in to reply
 

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