/**

  • Definition for singly-linked list.

  • struct ListNode {

  • int val;
    
  • ListNode *;
    
  • ListNode(int x) : val(x), next(NULL) {}
    
  • }; */ class Solution { public: bool hasCycle(ListNode *head) {

     if(head == nullptr || head->next == nullptr)  return 0;
     
     ListNode *slow = head;
     ListNode *fast = head;
     
     while(fast->next && fast->next->next)
     {
         fast= fast->next->next;
          slow= slow->next;
        if(slow == fast)
         {
             return 1;
         }
        
         
     }
    
     return 0;
     
    

    } };