leetCode142:(python)

leetCode142:(python),第1张

leetCode142:(python)

解答

class Solution:
    def detectCycle(self, head):
        if head is None or head.next is None or head.next.next is None:
            return None
        fast = head
        slow = head
        while fast and fast.next:
            fast = fast.next.next
            slow = slow.next
            if fast == slow:
                fast = head
                while fast != slow:
                    slow = slow.next
                    fast = fast.next
                return fast

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5711619.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存