如果有环快指针一定可以追上慢指针。如果没有环快指针一定可以指向nullptrnullptrnullptr从而结束循环。classSolution{public:boolhasCycle(ListNode*head){ListNode*slowhead;ListNode*fasthead;if(headnullptr||head-nextnullptr){returnfalse;}while(fast!nullptrfast-next!nullptr){slowslow-next;fastfast-next-next;if(slowfast){returntrue;}}returnfalse;}};