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:

 

0 0 votes
Article Rating