Skip to content

Commit d68994b

Browse files
authored
Merge pull request #192 from saurabhcommand/master
Adding 141.cpp
2 parents de21d48 + 7d9ce56 commit d68994b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

leetcode/cpp/linkedlist/141.cpp

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

0 commit comments

Comments
 (0)