程序员面试题精选100题(35)-两链表的第一个公共结点[数据结构]

面试题 时间:2019-09-22 手机网站
      ListNode *pFisrtCommonNode = NULL;

      if(pListHeadLong == pListHeadShort)

            pFisrtCommonNode = pListHeadLong;

 

      return pFisrtCommonNode;

}

 

///////////////////////////////////////////////////////////////////////

// Get the length of list with head pHead

// Input: pHead - the head of list

// Return: the length of list

///////////////////////////////////////////////////////////////////////

unsigned int ListLength(ListNode* pHead)

{

      unsigned int nLength = 0;

      ListNode* pNode = pHead;

      while(pNode != NULL)

      {

            ++ nLength;

            pNode = pNode->m_pNext;

      }

 

      return nLength;

}