Linked List Cycle

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Linked List — Pointer Surgery

Redraw next pointers carefully; draw on paper first.

ListNode* prev = nullptr;
ListNode* cur = head;
while (cur) {
    ListNode* nxt = cur->next;
    cur->next = prev;
    prev = cur;
    cur = nxt;
}
return prev;
Linked List

Linked List Cycle

Easy
LeetCode
3/3
EasyLinked ListLeetCode #141

Linked List Cycle

Floyd: slow +1, fast +2. Meet ⇒ cycle.

Examples

Example 1

Input

4 1
3 2 0 -4

Output

true
Example 2

Input

2 -1
1 2

Output

false

Stuck? Take a nudge

C++17