剑指offer---链表中环的入口结点

class Solution
{
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead)
    {
        vector<ListNode*> vec;
        ListNode* list = NULL;
        if (pHead == NULL)    return NULL;
        int flag = 0;
        while (pHead != NULL)
        {
            vec.push_back(pHead);
            pHead = (pHead->next);
            for (int i = 0; i < vec.size(); ++i)
            {
                if (pHead == vec[i])
                {
                    list = pHead;
                    flag = 1;
                    break;
                }
            }
            if (flag == 1) break;
        }
        return list;
        
    }
};
原文地址:https://www.cnblogs.com/159269lzm/p/7260610.html