Remove Nth Node From End of List
LeetCode 19 • Medium • Linked Lists
Remove the n-th node from the end. Dummy + two pointers: move fast n steps, then move both until fast.next is null.
TimeO(L)single pass
SpaceO(1)two pointers
Slow: —
Fast: —
Slow
Fast
To remove
Slow
—
Fast
—
Result
pending
Ready
Press Play. Dummy node + two pointers. Move fast n steps ahead, then move both until fast.next is null. slow.next = slow.next.next.