The linked list data structure: the double pointer Problems

Dual / multiple pointer list the problems, the problem of ring

一、Find the Middle Node

 1 def find_middle(lst):
 2     assert lst.head is not None and lst.head.next is not None
 3 
 4     head = lst.head
 5     fast = head
 6     slow = head
 7 
 8     while fast is not None and fast.next is not None:
 9         fast = fast.next.next
10         slow = slow.next
11 
12     return slow.value

 

Guess you like

Origin www.cnblogs.com/liushoudong/p/12350579.html