Cycle Detection

  • + 0 comments

    Only python works for me...

    Floyd cycle approach

    def has_cycle(head):
        slow = head
        fast = head
        
        while fast is not None and fast.next is not None:
            slow = slow.next
            fast = fast.next.next
            
            if (slow == fast):
                return 1
        
        return 0