Skip to content

Commit 5dca12a

Browse files
Time: 243 ms (5.06%), Space: 8.9 MB (16.69%) - LeetHub
1 parent 7b642d6 commit 5dca12a

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
bool hasCycle(ListNode *head) {
12+
vector<ListNode*> vec;
13+
while(head)
14+
{
15+
vector<ListNode*>::iterator it;
16+
it = find (vec.begin(), vec.end(), head);
17+
if (it != vec.end())
18+
{
19+
return true;
20+
}
21+
else
22+
vec.push_back(head);
23+
head = head->next;
24+
}
25+
return false;
26+
27+
}
28+
};

0 commit comments

Comments
 (0)