首页 > 其他 > 详细

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

时间:2017-07-30 22:56:26      阅读:199      评论:0      收藏:0      [点我收藏+]
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;
        
    }
};

 

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

原文:http://www.cnblogs.com/159269lzm/p/7260610.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!