class Solution { public: bool hasCycle(ListNode *head) { if (head == NULL) return NULL; //空表 ListNode *slow = head; ListNode *fast = head; while (fast&&fast->next){ slow = slow->next; fast = fast->next->next; if (slow == fast)return true; //相遇 } return false; } };