eolymp
bolt
Try our new interface for solving problems
Problems

LinkedList Cycle

published at 6/25/22, 3:52:08 pm

int hasCycle(ListNode head) { if(head==NULL) return 0; ListNode p=head; ListNode* q=head; while(q->next && q->next->next){ p=p->next; q=q->next->next; if(p==q) return 1;
} return 0; }

published at 4/3/24, 2:42:07 am

int hasCycle(ListNode head) { if (head == NULL) return 0; ListNode p = head; ListNode* q = head; while (q->next && q->next->next) { p = p->next; q = q->next->next; if (p == q) return 1; } return 0; }