floyd circle detection algorithm(龟兔赛跑算法)

class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        try:
            slow = head
            fast = head.next
            while slow is not fast:
                slow = slow.next
                fast = fast.next.next
            return True
        except:
            return False

 

相关文章:

  • 2022-02-11
  • 2021-09-02
  • 2021-09-14
  • 2021-12-05
  • 2022-01-06
  • 2021-09-22
  • 2021-12-16
猜你喜欢
  • 2021-07-08
  • 2022-02-02
  • 2022-01-05
  • 2021-10-04
  • 2022-01-09
  • 2021-04-23
  • 2022-03-08
相关资源
相似解决方案