[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/mJackie/leetcode/master/code/lc160.java [Back]  [Original]

package code;
/*
 * 160. Intersection of Two Linked Lists
 * 
 * Easy
 * LinkedList
 * 1.xx 2.cur
 * Tips
 */
public class lc160 {
    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if(headA==null||headB==null)
            return null;
        ListNode curA = headA;
        ListNode curB = headB;
        while (curA != curB) {
            if(curA == null)
                curA = headB;
            if(curB == null)
                curB = headA;
            if(curA==curB)
                return curA;    //
            curA = curA.next;
            curB = curB.next;
        }
        return curA;
    }
}

Web Proxy Viewer  |  New URL  |  Original Page