python如何判断单向链表中是否有环【面试题详解】【附代码】

今天爱分享给大家带来python如何判断单向链表中是否有环【面试题详解】【附代码】,希望能够帮助到大家。


# 快慢指针
class Solution(object):
    def hasCycle(self, head):
        if(head == None or head.next == None):
            return False
        node1 = head
        node2 = head.next
        while(node1 != node2):
            if(node2 == None or node2.next == None):
                return False
            node1 = node1.next
            node2 = node2.next.next

        return True

原文链接:https://blog.itblood.com/4580.html,转载请注明出处。
0
年轻黑帮老板莉莉卡的妓院管理[PC+安卓/1.23G] [日系RPG/AI汉化]
年轻黑帮老板莉莉卡的妓院管理[PC+安卓/1.23G] [日系RPG/AI汉化]
3分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?