ENHI
Admin
P
Primitive
A Cloudflare-native knowledge workspace for folders, topics, snippets, revisions, and file assets.
Overview
Medium15 minpublished

Reverse Linked List

Reverse a singly linked list by maintaining three pointers: prev, curr, and next. Redirect each node to its predecessor, then advance the window. Runs in O(n) time with O(1) extra space.

Visualization
123
Interactive visualization configs are stored as JSON in D1 and can be extended without schema changes.
Implementation
def reverseList(head):
    prev, curr = None, head
    while curr:
        nxt = curr.next
        curr.next = prev
        prev, curr = curr, nxt
    return prev
Revision
Published and draft snapshots will appear here after edits.