Linked List Cycle II LeetCode solution in C++

1
class Solution {
2
public:
3
ListNode *detectCycle(ListNode *head) {
4
map<ListNode *, int> m;
5
int index = 0;
6
while (head) {
7
if (m.find(head) == m.end())
8
m[head] = index;
9
else
10
return (head);
11
head = head->next;
12
index++;
13
}
14
return (NULL);
15
}
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0