Share my 6-lines java solution


  • 1
    C
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode pa, pb, ta, tb;
        for(ta=headA, tb=headB; ta != null && tb != null; ta=ta.next, tb=tb.next);
        for(pa=headA; ta!=null; ta=ta.next, pa=pa.next);
        for(pb=headB; tb!=null; tb=tb.next, pb=pb.next);
        for(; pa!=pb; pa=pa.next, pb=pb.next);
        return pa;
    }

Log in to reply
 

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