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

相关推荐
春弦_4 小时前
自用算法整理二
数据结构·算法·图论
java_nnnn5 小时前
LeetCode刷题滑动窗口(串联所有单词的子串+最小覆盖的子串)Java
算法·leetcode·职场和发展
Navigator_Z6 小时前
LeetCode //C - 1301. Number of Paths with Max Score
c语言·算法·leetcode
Nuanyt8 小时前
LeetCode Hot100 刷题笔记 · 普通数组专题
java·笔记·算法·leetcode
xxxiugou1239 小时前
链表算法题精讲:从两数相加到K组翻转
数据结构·c++·算法·链表
春弦_10 小时前
LeetCode Hot 100 刷题笔记
笔记·leetcode·哈希算法
凯瑟琳.奥古斯特13 小时前
力扣1015C++解法技巧
c++·算法·leetcode·链表·职场和发展
悠仁さん13 小时前
【算法C++】双指针(一)
数据结构·c++·算法
文丑颜不良啊13 小时前
LeetCode626~650题目解析
java·leetcode
YukiRinLL13 小时前
字符串存储与 BF、KMP 匹配算法
数据结构·算法