← All problems

Reverse Linked List

easy

Given the head of a singly linked list, reverse it and return the new head.

Nodes look like { val, next }. In the examples below, lists are shown as plain arrays for readability — AlgoLens converts them to real linked-list nodes before your function runs.

Example

Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Loading...