LeetCode The Hard Way

Linked List

Linked list templates for common pointer techniques such as Floyd's fast and slow pointers.

Floyd's fast and slow pointer

ListNode* slow = head;
ListNode* fast = head;
while (fast != nullptr && fast->next != nullptr) {
    // do something here
    slow = slow->next;
    fast = fast->next->next;
}

On this page