3
bool hasCycle(ListNode *head) {4
// if head is NULL then return false;5
if (head == NULL) return false;7
// making two pointers fast and slow and assignning them to head11
// till fast and fast-> next not reaches NULL12
// we will increment fast by 2 step and slow by 1 step13
while (fast != NULL && fast->next != NULL) {14
fast = fast->next->next;17
// At the point if fast and slow are at same address18
// this means linked list has a cycle in it.19
if (fast == slow) return true;22
// if traversal reaches to NULL this means no cycle.