题解 | #链表中环的入口结点#
链表中环的入口结点
https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def EntryNodeOfLoop(self, pHead):
# write code here
# a+b+c+b=2*(a+b)
# a+b+(b+c)n=2(a+b)
slow = pHead
fast = pHead
while fast != None and fast.next != None:
fast = fast.next.next
slow = slow.next
if fast == slow:
while pHead != slow:
pHead = pHead.next
slow = slow.next
return slow
return None
#23届找工作求助阵地#
顺丰集团工作强度 379人发布