/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
public:
    ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
        if(pHead1==pHead2) return pHead1;
        ListNode* temp1 = pHead1, *temp2 = pHead2, *pmax, *pmin, *temp3, *temp4;
        int sz1=0, sz2=0, min=0, max=0, idx=0;
        
      	//第一步: 找到并定位到较长链表和较短链表右对齐后左边的开始节点(长链表序号为max_si***_size+1的位置)
        while(temp1&&temp2){
            temp1 = temp1->next;
            temp2 = temp2->next;
        }
        temp3 = temp1==nullptr?pHead2:pHead1;
        temp4 = temp1!=nullptr?temp1:temp2;
        while(temp4){
            temp3 = temp3->next;
            temp4 = temp4->next;
        }
        
      	//第二步: 两个链表现在在同一个起点,依次遍历即可
        temp4 = temp1==nullptr?pHead1:pHead2;
        
        while(temp3){
            if(temp3==temp4) return temp3;
            temp3 = temp3->next;
            temp4 = temp4->next;
        }

        return nullptr;
        
       
    }
};