zoukankan      html  css  js  c++  java
  • 环形链表

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    class Solution:
        def hasCycle(self, head: ListNode) -> bool:
     
      #哈希表
            # hashmap = [] #因为存的是地址
            # if head is None or head.next is None:
            #     return False
            # while head:
            #     if head in hashmap:
            #         return True
            #     else:
            #         hashmap.append(head)
            #         head = head.next
            # return False    
            # 
            #双指针
            if head is None or head.next is None:
                return False
            slow = fast = head
            while slow and fast and fast.next:
                slow = slow.next
                fast = fast.next.next
                if slow is fast:
                    return True
            return False
  • 相关阅读:
    python两个类之间变量和函数的调用
    ubuntu远程桌面设置
    ROS节点分布式运行方法
    pandaboard串口通信调试
    linux下查看cpu使用情况
    树莓派LED指示灯说明
    python多线程实践小结
    关系模型关系模型
    栈和队列的应用
    栈和队列
  • 原文地址:https://www.cnblogs.com/shamoguzhou/p/15306508.html
Copyright © 2011-2022 走看看