哈希表 class Solution { public: ListNode *detectCycle(ListNode *head) { unordered_set<ListNode*>hashset; while(head){ if(hashset.count(head)){ return head; } hashset.insert(head); head=head->next; } return NULL; } };