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

链表中环的入口结点

http://www.nowcoder.com/questionTerminal/253d2c59ec3e4bc68da16833f79a38e4

class Solution:
    def EntryNodeOfLoop(self, pHead):
        # write code here
        if  not pHead:
            return None
        start = pHead
        dic = {}
        while start:
            if start in dic:
                return start
            else:
                dic[start] = start.val
            start = start.next
        return None
全部评论

相关推荐

EEbond:给北邮✌️跪了
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

更多
牛客网
牛客企业服务