链表中环的入口结点

链表中环的入口结点

 1 # -*- coding:utf-8 -*-
 2 # class ListNode:
 3 #     def __init__(self, x):
 4 #         self.val = x
 5 #         self.next = None
 6 class Solution:
 7     def EntryNodeOfLoop(self, pHead):
 8         # write code here
 9         plist = []
10         while pHead:
11             if pHead in plist:
12                 return pHead
13             else:
14                 plist.append(pHead)
15             pHead = pHead.next

 

上一篇:算法总结


下一篇:分割链表