# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

#
# 
# @param pHead1 ListNode类 
# @param pHead2 ListNode类 
# @return ListNode类
#
class Solution:
    def FindFirstCommonNode(self , pHead1 , pHead2 ):
        # write code here
        cur1 = pHead1
        cur2 = pHead2
        if not cur1 or not cur2: #任一链表为空,返回空
            return None
        while cur1:
            while cur2:
                if cur1 == cur2:#嵌套循环,外层遍历cur1链表,内层遍历cur2链表,依次比较。
                    return cur1
                cur2 = cur2.next 
            cur1 = cur1.next 
            cur2 = pHead2