Skip to content

Commit cc59335

Browse files
committed
Linked List Cycle solution
1 parent b0fbfbf commit cc59335

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

linked-list-cycle/PDKhan.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
bool hasCycle(ListNode *head) {
4+
ListNode* slow = head;
5+
ListNode* fast = head;
6+
7+
while(fast && fast->next){
8+
slow = slow->next;
9+
fast = fast->next->next;
10+
11+
if(slow == fast)
12+
return true;
13+
}
14+
15+
return false;
16+
}
17+
};

0 commit comments

Comments
 (0)