141. 环形链表 - 力扣(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 hasCycle(self, head):
        seen = set()
        node = head
        while node:
            if node in seen:
                return True
            seen.add(node)
            node = node.next
        return False

结果

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

相关推荐
li星野20 小时前
刷题:数组
数据结构·算法
@BangBang1 天前
leetcode (4): 连通域/岛屿问题
算法·leetcode·深度优先
Mr_pyx1 天前
【LeetCode Hot 100】 除自身以外数组的乘积(238题)多解法详解
算法·leetcode·职场和发展
故事和你911 天前
洛谷-数据结构-1-3-集合3
数据结构·c++·算法·leetcode·贪心算法·动态规划·图论
自我意识的多元宇宙1 天前
二叉树的遍历和线索二叉树--线索二叉树
数据结构
ulias2121 天前
leetcode热题 - 3
c++·算法·leetcode·职场和发展
菜鸟丁小真1 天前
LeetCode hot100-287.寻找重复数和994.腐烂的橘子
数据结构·算法·leetcode·知识点总结
笨鸟先飞的橘猫1 天前
数据结构学习——跳表
数据结构·python·学习
Pentane.1 天前
【力扣hot100】【Leetcode 15】三数之和|暴力枚举 双指针 算法笔记及打卡(14/100)
数据结构·笔记·算法·leetcode
Mr_pyx1 天前
【LeetCode Hot 100】 - 缺失的第一个正数完全题解
数据结构·算法