数据结构之链表:双指针问题

链表中的双/多指针问题,环的问题

一、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

猜你喜欢

转载自www.cnblogs.com/liushoudong/p/12350579.html