Starting Point of Cycle in Linked List

PHOTO EMBED

Tue May 28 2024 22:54:02 GMT+0000 (Coordinated Universal Time)

Saved by @ayushg103 #c++

 ListNode *hasCycle(ListNode *head) {
        ListNode *slow=head;
        ListNode *fast=head;
      while(fast!=NULL && fast->next!=NULL)
      {
        slow=slow->next;
        fast=fast->next->next;
        if(fast==slow)
        return slow;
      }
     return NULL;
    }
    ListNode *detectCycle(ListNode *head) {
         ListNode *t1=hasCycle(head);
         if(t1==NULL)return NULL;
        ListNode *t=head;
       

        while(t!=t1)
        {
            t=t->next;
            t1=t1->next;
        }
        return t;
        
    }
content_copyCOPY