Skip to content

Commit e76932c

Browse files
Day 15 Floyd Cycle Detection
1 parent 0ef0feb commit e76932c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Arrays/FloydsCycleDetection.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
using namespace std;
3+
bool floydCycleDetection(Node* root){
4+
// we will create two pointers.
5+
Node *slow=Node* fast = root;
6+
while(slow and fast and fast->next){
7+
slow=slow->next;
8+
fast=fast->next->next;
9+
if(slow==fast){
10+
return true;
11+
}
12+
return false;
13+
}
14+
}
15+
void main(){
16+
cout << floydCycleDetection();
17+
}

0 commit comments

Comments
 (0)