快慢指针 模板 - lifengyu360/lifengyu_first_git_test GitHub Wiki

// Initialize slow & fast pointers

ListNode* slow = head; ListNode* fast = head;

while (slow && fast && fast->next)

{ slow = slow->next; // move slow pointer one step each time fast = fast->next->next; // move fast pointer two steps each time

if (slow == fast) {         // change this condition to fit specific problem
    return true;
}

}

return false; // change return value to fit specific problem