/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Solution { public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) { ListNode cur1 = pHead1; ListNode cur2 = pHead2; if(pHead1==null||pHead2==null){ return null; } //链表并不相同长度所以不能一起遍历 //两种做法,1遍历一遍统计长度,2。双 //指针链接fa,链接之后两个指针一定会相遇如果有公共节点 //也有可能cur1小于粗人的长度 while(cur1!=cur2){ cur1 = cur1 == null ? pHead2 : cur1.next; cur2 = cur2 == null ? pHead1 : cur2.next; } return cur1; } }