import java.util.*;
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
if(pHead1==null)return null;
if(pHead2==null) return null;
ListNode tm1 = pHead1;
ListNode tm2 = pHead2;
// if(pHead1.next.next.next==pHead2.next.next){
// return null;
// }
while (pHead1 != pHead2) {
pHead1 = pHead1.next;
pHead2 = pHead2.next;
if(pHead1==null&&pHead2==null){
return null;
}
if (pHead1 == null) {
pHead1 = tm2;
}
if (pHead2 == null) {
pHead2 = tm1;
}
}
return pHead1;
}
}
//我看了题解