Reverse a Linked List

Linked Lists · medium

Nodes are `{ val, next }` objects. Implement `reverseList(head)` that reverses a linked list in-place and returns the new head. Example: `1→2→3→null` becomes `3→2→1→null`.

Hints
  • Keep track of `prev`, `curr`, and `next` as you traverse.
  • At each step: save `curr.next`, point `curr.next` to `prev`, then advance both pointers.

Learning resources

Loading...

Run your code to see results.