Loading problemβ¦
Given head, the head of a linked list, determine if the linked list has a cycle in it.
There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer.
Return true if there is a cycle in the linked list. Otherwise, return false.
Detect whether a linked list contains a cycle using Floyd's Tortoise and Hare algorithm β a two-pointer technique where one pointer moves twice as fast as the other.
true if the list has a cycle, false otherwise// List: 3 β 2 β 0 β -4 β (back to 2) β true
// List: 1 β 2 β null β false