剑指offer python版 链表中环的入口结点

class Solution:
    def EntryNodeOfLoop(self, pHead):
        pFast = pHead
        pSlow = pHead
        while pFast != None and pFast.next != None:
            pFast = pFast.next.next
            pSlow = pSlow.next
            if pFast == pSlow:
                break
        if pFast == None or  pFast.next == None:
            return None
        pFast = pHead
        while (pFast != pSlow):
            pFast = pFast.next
            pSlow = pSlow.next
        return pFast
        # write code here

 

posted @ 2018-10-25 16:58  findtruth123  阅读(295)  评论(1编辑  收藏  举报