Intersection of Two Linked Lists 2020-09-18 08:18

Problem Description

public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
     if (headA == null || headB == null) {
        return null;
    }
    ListNode pA = headA;
    ListNode pB = headB;
    while (pA != pB) {
        pA = pA == null ? headB : pA.next;
        pB = pB == null ? headA : pB.next;
    }
    return pA;
}
Runtime Memory
1 ms 41.5 MB

henryxi leetcode list

EOF