/** 取巧方法,因为链表的每一个val的绝对值都小于100000,所以将遍历过的都变成100001即可分辨这个点十分成环回来。 class Solution { public: bool hasCycle(ListNode *head) { for(ListNode * temp=head;;temp=temp->next){ if(temp == nullptr) return false; if(temp->val == 100001) return true; temp->val = 100001; } } };