Detect vòng lặp trong linked list bằng python

def has_cycle(head):
    slow = head
    fast = head

    while fast != None:
     slow = slow.next

     if fast.next != None:
          fast = fast.next.next
     else:
          return False

     if slow is fast:
          return True

    return False


Video tham khảo:

[embed]https://www.youtube.com/watch?v=_BG9rjkAXj8[/embed]

 

No comments yet