LeetCode 206 Reverse Linked List - Implementation

The approach

Three pointers: prev, curr, next. Reverse each arrow as you traverse.

function reverseList(head): prev = null curr = head while curr: next = curr.next curr.next = prev prev = curr curr = next return prev

O(n)O(n) time, O(1)O(1) space.