题目来自编程之美
题目:统计有环单链表的环中结点个数
思路:参考单链表面试题
代码
/*思路:在快慢指针相遇位置肯定是在环中,此时一个指针不动,让另一个指针转圈,再次相遇时经过的结点个数就是环中结点个数*/
int GetCountOfCycle(ListNode* pHead)
{
assert(pHead != NULL);
ListNode* pFast = pHead;
ListNode* pSlow = pHead;
int nCount = 1;//第一个结点是相遇点
while (pFast->m_pNext && pFast->m_pNext->m_pNext)
{
pFast = pFast->m_pN