#include <stdbool.h> /** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * * @param head ListNode类 * @return bool布尔型 */ bool hasCycle(struct ListNode* head ) { // write code here struct ListNode*list = head,*fast = head; while(fast&&fast->next) { list = list->next; fast = fast->next->next; if(list==fast) { return true; } } return false; }