如果p1==p2,则这个节点就是公共节点(注意不是值)
public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2)
{
ListNode p1 = pHead1;
ListNode p2 = pHead2;
if(p1==null || p2 ==null)return null;
while(p1 != p2)
{
{
ListNode p1 = pHead1;
ListNode p2 = pHead2;
if(p1==null || p2 ==null)return null;
while(p1 != p2)
{
//记住这里一定是if else,不能省去else,要严谨
if(p1 == null)
{
p1 = pHead2;
}else p1 = p1.next;
{
p1 = pHead2;
}else p1 = p1.next;
if(p2 == null)
{
p2 = pHead1;
}else p2 = p2.next;
}
return p1;
}