Asking help for my C code according to the solution


  • 0
    S

    Hi all, I was trying to implement the solution into C code, but changed bunch of times still getting errors.
    Could someone give me some suggestions on my code?
    I really appreciate your help.
    Thanks!

    struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
    struct ListNode *p1 = headA;
    struct ListNode *p2 = headB;
    int a_end = 1;
    int b_end = 1;
    if (!p1 || !p2) return NULL;
    while(1) {
        int a = p1->val;
        int b = p2->val;
        if(a == b) return p1;
        p1 = p1->next;
        p2 = p2->next;
        if(!p1) {
            p1 = headB;
            p2 = p2->next;
            a_end = a;
        }
        if(!p2) {
            p2 = headA;
            p1 = p1->next;
            b_end = b;
        }
        if(a_end != b_end) return NULL;
    }

  • 0
    L
    This post is deleted!

  • 0
    L
    This post is deleted!

Log in to reply
 

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