Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

new listnode(0) meaning

public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
    int sizeA = 0, sizeB = 0;
    ListNode ptrA = headA, ptrB = headB;

    while (ptrA != null) {
        ptrA = ptrA.next;
        sizeA++;
    }

    while (ptrB != null) {
        ptrB = ptrB.next;
        sizeB++;
    }

    int diff = sizeA - sizeB;
    if (diff > 0) {
        while (diff-- > 0) {
            headA = headA.next;
        }
    } else {
        while (diff++ < 0) {
            headB = headB.next;
        }
    }

    while (headA != headB) {
        headA = headA.next;
        headB = headB.next;
    }

    return headA;
}
Source by www.hackingnote.com #
 
PREVIOUS NEXT
Tagged: #meaning
ADD COMMENT
Topic
Name
2+1 =