"""
Definition of ListNode
class ListNode(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
"""
@param head: The first node of the linked list.
@return: The node where the cycle begins.
if there is no cycle, return null
"""
def detectCycle(self, head):
# write your code here
L = []
p1 = head
while p1 != None:
if p1 not in L:
L.append(p1)
p1 = p1.next
else:
return p1
return None
LintCode: 带环链表 II
最新推荐文章于 2021-02-16 12:39:30 发布