142. 环形链表 II - 力扣(LeetCode)

代码

python 复制代码
# encoding = utf-8
# 开发者:Alen
# 开发时间: 20:16
# "Stay hungry,stay foolish."

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def detectCycle(self, head):
        seen = set()
        node = head
        while node:
            if node in seen:
                return node
            seen.add(node)
            node = node.next
        return None

结果

解题步骤:https://www.bilibili.com/video/BV1SdXxBsEWM/?vd_source=15b4bc8968fa5203cc470cb68ff72c96

相关推荐
鹿角片ljp1 小时前
LeetCode 46. 全排列|吃透回溯
算法·leetcode·职场和发展
石头猫灯2 小时前
WordPress wp2shell 漏洞链完整拆解流程
网络·数据结构·安全·web安全
.道阻且长.4 小时前
11.LeetCode算法习题讲解--滑动窗口--将x减到0的最小操作数
算法·leetcode·职场和发展
wenyq74 小时前
LeetCode 2460. Apply Operations to an Array
算法·leetcode
青 春 记 忆5 小时前
LeetCode 142. 环形链表 II|Python 解法详解
python·leetcode·链表
小欣加油6 小时前
leetcode3069 将元素分配到两个数组中I
数据结构·c++·算法·leetcode·职场和发展
_Narcissus_9 小时前
排序算法总结表格
c语言·数据结构·c++·笔记·算法·排序算法·总结
一只小小的芙厨10 小时前
前缀和与差分
数据结构·算法
从琳开始98910 小时前
优选算法——双指针(算法原理+力扣题)
算法·leetcode·职场和发展
从琳开始98910 小时前
优选算法——滑动窗口(概念+解题模板+LeetCode例题讲解)
算法·leetcode·职场和发展