/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: bool hasCycle(ListNode *head) { unordered_set<ListNode*> c; while(head != NULL){ if(c.count(head)){ return true; } c.insert(head); head = head -> next; } return false; } }; 标签:head,ListNode,int,环形,next,链表,return From: https://www.cnblogs.com/hbro/p/17386046.html