Intersection

经典题目

160 Intersection of Two Linked Lists

public class Solution {
    public ListNode getIntersectionNode(ListNode one, ListNode two) {
        if (one == null || two == null) return null;
        
        ListNode i = one;
        ListNode j = two;

        while(i != j) {
            i = i == null ? two : i.next;
            j = j == null ? one : j.next;
        }

        return i;
    }
}

Last updated