链表中环的入口节点
2019-12-22 本文已影响0人
而立之年的技术控
![](https://img.haomeiwen.com/i13792534/59e6a75e2927a252.jpg)
class Solution:
def EntryNodeOfLoop(self, pHead):
# write code here
if pHead is None or pHead.next is None:
return None
fast = pHead
slow = pHead
while fast and fast.next:
fast = fast.next.next
slow = slow.next
if fast == slow:
break
fast = pHead
while fast != slow:
fast = fast.next
slow = slow.next
return fast