2021年9月8日10:31:08
2021年9月8日10:40:58

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class Solution {
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        int len1 = 0;
        int len2 = 0;

        ListNode cur1 = pHead1;
        ListNode cur2 = pHead2;
        while(cur1 != null){cur1 = cur1.next; len1++;}
        while(cur2 != null){cur2 = cur2.next; len2++;}

        cur1 = pHead1;
        cur2 = pHead2;

        if(len1>len2){
            while(len1!=len2){cur1 = cur1.next;len1--;}
        }
        else{
            while(len1!=len2){cur2 = cur2.next;len2--;}
        }

        while(cur1!=null && cur2!=null){
            if(cur1 == cur2) return cur1;
            else{
                cur1 = cur1.next;
                cur2 = cur2.next;
            }
        }
        return null;
    }
}