Nine Chapters count judges Net-original website
http://www.jiuzhang.com/problem/28/
Topics
First Order: Give a single-linked list to determine if the single-linked list has a ring, such as 1->2->3->4->2 is a linked list of existing rings. Additional space required to use O (1).
Advanced: Find the entrance of the ring. Additional Space for O (1) is also required.
Answer
First order: With two pointers, starting from the list head, a slow pointer each step, another fast hand two steps each time. Until they meet (with a ring) or the quick pointer goes to null (no ring).
Advanced: After meeting, move a pointer to the list head, two pointers each move one step at a time, until meet again, the meeting point is the ring entrance.
Interviewer Angle
The problem of fast and fast pointers is not common, the problem with this idea in addition to the chain list to find the ring, there is a list to find the midpoint (require a scan). This problem belongs to the problem of examination, also belongs to I know to know, do not know the problem. Let's remember the answer to this question. Specific analysis, the reader can self-calculation on paper.
Nine-chapter algorithm surface examination Questions 28 chain list to find the ring