1class 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 else10 return (head);11 head = head->next;12 index++;13 }14 return (NULL);15 }16};
WPM •0 •0
ACC •0 •0
TIME •0