1.编辑器

我使用的是win10+vscode+leetcode+python3
环境配置参见我的博客:
链接

2.第一百四十一题

(1)题目
英文:
Given a linked list, determine if it has a cycle in it.

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

中文:
给定一个链表,判断链表中是否有环。

为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在该链表中没有环。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/linked-list-cycle

(2)解法
① 一个一个地试探
(耗时:1116ms,内存:16.6M)

class Solution:def hasCycle(self, head: ListNode) -> bool:if not head:return headm = []while head:if head in m:return Truem.append(head)head = head.nextreturn False

② 双指针
(耗时:76ms,内存:16.8M)

class Solution:def hasCycle(self, head: ListNode) -> bool:if not head:return headslow = headquick = headwhile quick and slow:slow = slow.nextif quick.next:quick = quick.next.nextelse:return Falseif quick is slow:return Truereturn False

leetcode python3 简单题141. Linked List Cycle相关推荐

  1. leetcode python3 简单题234. Palindrome Linked List

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百三十四题 (1)题目 英文: Given a singly linked li ...

  2. leetcode python3 简单题206. Reverse Linked List

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百零六题 (1)题目 英文: Reverse a singly linked l ...

  3. leetcode python3 简单题203. Remove Linked List Elements

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百零三题 (1)题目 英文: Remove all elements from ...

  4. leetcode python3 简单题160. Intersection of Two Linked Lists

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百六十题 (1)题目 英文: Write a program to find t ...

  5. leetcode python3 简单题21. Merge Two Sorted Lists(Linked)

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二十一题 (1)题目 英文: Merge two sorted linked li ...

  6. leetcode python3 简单题225. Implement Stack using Queues

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十五题 (1)题目 英文: Implement the following ...

  7. leetcode python3 简单题202. Happy Number

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百零二题 (1)题目 英文: Write an algorithm to det ...

  8. leetcode python3 简单题83. Remove Duplicates from Sorted List

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第八十三题 (1)题目 英文: Given a sorted linked list ...

  9. leetcode python3 简单题70. Climbing Stairs

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: You are climbing a stair ca ...

最新文章

  1. Linux的常用命令!
  2. Codeforces Round #308 (Div. 2) C. Vanya and Scales dfs
  3. 一对多和多对一的关系,用mybatis写
  4. CSS魔法堂:更丰富的前端动效by CSS Animation
  5. oracle数据库相关知识,Oracle数据库相关知识点复习
  6. 广告贴:本周六的SharePoint技术交流会
  7. JavaScript -- DOM树
  8. cad lisp 示坡线_AutoCAD命令-画示坡线
  9. AdapterView 及其子类
  10. sony 播放器 android,WALKMAN × 安卓9.0,索尼 NW-ZX505 播放器体验
  11. Twitter是什么软件?哪个国家的?怎么使用?免费吗?
  12. [TCP/IP] 基础知识总结
  13. Idea中怎么运行从github上下载的项目
  14. Type c手机怎么实现一边充电一边听歌(边充边听放方案)
  15. 神经网络ppt不足之处怎么写,神经网络ppt免费下载
  16. nodejs 实现二维码生成及图片合成
  17. 【STM32】标准库与HAL库对照学习教程外设篇--红外避障传感器
  18. python 检测行为 网络摄像头_使用Python扫描开放的网络摄像头
  19. 网安--第七章 恶意代码分析与防治
  20. 谢宾斯基三角形的几种生成方法

热门文章

  1. python参数的解包(拆包)(一分钟读懂)
  2. 1433 mssql 安全_mssqlsql2008安全配置又一给力教程
  3. jQuery 基本效果
  4. 计算机组成原理 第六章 总线
  5. Tensorflow:TensorFlow基础(一)
  6. Python之倒序访问list
  7. ResNest网络系列
  8. 关于Python、Anaconda、Jupyter
  9. J2EE代码存档--导出Excel
  10. 分析“HTTP500内部服务器错误”解决方法