141. Linked List Cycle
Given head
, the head of a linked list, determine if the linked list has a cycle in it.
Return true
if there is a cycle in the linked list. Otherwise, return false
.
Example:

def hasCycle(head: Optional[ListNode]):
slow = head;
fast = head;
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False
Comments
Post a Comment