其实最初有点懵逼,这种题老是读不懂,其实就是找重复节点
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def EntryNodeOfLoop(self, pHead):
# write code here
stack = []
while pHead:
stack.append(pHead)
pHead = pHead.next
if pHead in stack:
return pHead
return None
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def EntryNodeOfLoop(self, pHead):
# write code here
stack = []
while pHead:
stack.append(pHead)
pHead = pHead.next
if pHead in stack:
return pHead
return None