思路:
Python:
# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def EntryNodeOfLoop(self, pHead): # write code here if not pHead: return None fast=pHead slow=pHead while fast and fast.next: slow=slow.next fast=fast.next.next if slow==fast: break if not fast or not fast.next: return None fast=pHead while fast!=slow: fast=fast.next slow=slow.next return fast