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

相关推荐
0+1111 小时前
算法 --模拟
c++·算法·leetcode
Nil2082 小时前
leetcode 739每日温度
算法·leetcode·职场和发展
lvwangshu2 小时前
势能分析(摊还分析)
数据结构·数学·算法
xqqxqxxq3 小时前
LeetCode Hot100 矩阵专题题解笔记
笔记·leetcode·矩阵
All for pursuit.4 小时前
【贪心-4】581.最短无序连续子数组
数据结构·c++·算法·leetcode
mmmmath_35 小时前
LeetCode.020.有效的括号
数据结构·算法·leetcode
垆边人似月.5 小时前
华为机考题:字符个数统计
数据结构·算法·华为
All for pursuit.6 小时前
【回溯-2】22.括号生成
数据结构·c++·算法·leetcode
longlongzihan6 小时前
LeetCode 1004.最大连续1的个数III 滑动窗口及动态规划题解
c++·算法·leetcode·dp·滑动窗口
Chen—LSN7 小时前
数据结构——拿捏复杂度
java·c语言·开发语言·数据结构·经验分享·笔记·算法