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; } };
时间: 2024-12-18 23:55:52