"Disclaimer: All rights reserved, please indicate the source of the reprint, do not use for commercial purposes. Contact mailbox: [Email protected] "
Topic Link:http://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4?rp=3&ru=/ta/coding-interviews& Qru=/ta/coding-interviews/question-ranking
Title Description
A linked list contains the ring, please find the link to the list of the entry node.
Ideas
and the problem is the same, detailed analysis in this:http://blog.csdn.net/libin1105/article/details/48267113
/*struct ListNode { int val; struct ListNode *next; ListNode (int x): val (x), Next (NULL) { }};*/class solution{public:listnode* entrynodeofloop (listnode* phead) { if (phead==nullptr | | phead->next==nullptr) return nullptr; ListNode *first = phead->next->next; ListNode *second = phead->next;if (first==nullptr) return Nullptr;while (first!=second) {first = First->next-> Next;second = second->next;if (first==nullptr | | first->next==nullptr) return nullptr;} Second = Phead;while (first!=second) {first = First->next;second = Second->next;} return second;};
Copyright NOTICE: This article is the original blogger article, if reproduced, please indicate the source
The entry node of the ring in the chain list of the "sword-point offer"