class Solution { public: ListNode* EntryNodeOfLoop(ListNode* pHead){ if (pHead == nullptr) return nullptr; auto back = pHead; auto pre = back->next; while(pre != nullptr){ if (pre <= back) return pre; back = pre; pre = pre->next; } return nullptr; } };
前后双指针法,步频都为1,当前指针到后指针之后时,前指针所指即为入口地址。
欢迎交流指正!!!