Each subpattern solves a specific type of problem. Click on a card to view its template.
Flip pointer directions iteratively or recursively — the core of most reorder problems.
Slow moves 1 step, fast moves 2 — cycle detection and midpoint finding.
A dummy node before the head eliminates edge cases for head removal and list building.
Merge sorted lists by comparing heads and stitching the smaller node first.
Rewire next pointers directly — no extra nodes, no copying values.
Create a gap of k between two pointers to find the kth-from-end or the intersection node.
Template for: Reversal
1// Iterative reversal — O(N) time, O(1) space2ListNode* reverseList(ListNode* head)3{4 ListNode* prev = nullptr;5 ListNode* curr = head;67 while (curr)8 {9 ListNode* next = curr->next; // save before overwriting1011 curr->next = prev; // flip pointer12 prev = curr; // advance prev13 curr = next; // advance curr14 }1516 return prev; // new head17}
LeetCode #206
LeetCode #92
LeetCode #25
LeetCode #24
LeetCode #141
LeetCode #142
LeetCode #876
LeetCode #143
LeetCode #234
LeetCode #19
LeetCode #21
LeetCode #82
LeetCode #86
LeetCode #23
LeetCode #148
LeetCode #147
LeetCode #328
LeetCode #61
LeetCode #138
LeetCode #237
LeetCode #160
LeetCode #287
LeetCode #146