Python | Leetcode Python题解之第141题环形链表

题目:

题解:

class Solution:
    def hasCycle(self, head: ListNode) -> bool:
        if not head or not head.next:
            return False
        
        slow = head
        fast = head.next

        while slow != fast:
            if not fast or not fast.next:
                return False
            slow = slow.next
            fast = fast.next.next
        
        return True

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-06-10 09:38:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-10 09:38:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-10 09:38:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-10 09:38:01       18 阅读

热门阅读

  1. node-mysql中占位符?的使用

    2024-06-10 09:38:01       10 阅读
  2. 007 CentOS 7.9 apache-tomcat-9.0.89安装及配置

    2024-06-10 09:38:01       10 阅读
  3. 设计模式-策略模式

    2024-06-10 09:38:01       10 阅读
  4. 密码学及其应用——安全邮件、公钥密码学和PKI

    2024-06-10 09:38:01       13 阅读
  5. 语法、语义、语用与向量化

    2024-06-10 09:38:01       10 阅读
  6. 给gRPC增加负载均衡功能

    2024-06-10 09:38:01       12 阅读
  7. websocket发送数据

    2024-06-10 09:38:01       8 阅读
  8. Spring (49)OpenFeign

    2024-06-10 09:38:01       10 阅读
  9. 神经网络----现有网络的下载和使用(vgg16)

    2024-06-10 09:38:01       7 阅读