← Problems

Reverse a Linked List

EASY
Problem⌘ K
Linked ListPointers

Reverse a Linked List

Given the head of a singly linked list, reverse the list in-place and return the new head. You may only change the links between existing nodes.

Example

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

Constraints

The number of nodes is in the range [0, 5000].-5000 ≤ Node.val ≤ 5000.

Think about

Try a first approach in the editor. Copilot reviews your actual code and asks one focused question when it finds a gap.

solution.c
Test resultsReady
$ Type your approach, then run the sample tests.
LIVE AI REVIEW · WAITING
Start typing or paste your attempt here.