链表中环的入口结点

###题目

写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。

解题思路

给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null。

代码实现

1
2
3
4
5
6
7
8
9
class Solution:
def EntryNodeOfLoop(self, pHead):
l = []
while pHead is not None:
if pHead in l:
return pHead
l.append(pHead)
pHead = pHead.next
return None