变量简洁正确完整思路
class Solution { public: ListNode *detectCycle(ListNode *head) { ListNode*L=head,*R=head; bool hadCircle=false; while(R&&R->next){ L=L->next; R=R->next->next; if(L==R){ hadCircle=true; break; } } if(hadCircle){ ListNode*ans=head; while(ans!=L)ans=ans->next,L=L->next; return ans; } return nullptr; } };
原文:https://www.cnblogs.com/zhouzihong/p/15096786.html