Reverse Linked List - aloalgo

Reverse Linked List

Medium

You are given the head of a singly linked list.

Your task is to reverse this linked list.

Return the head of the newly reversed list.

Example 1

Input
1 → 2 → 3 → null
Output
3 → 2 → 1 → null
Explanation:

The list is reversed node by node.

Example 2

Input
1 → 2 → null
Output
2 → 1 → null
Explanation:

A two-node list is reversed.

Example 3

Input
None
Output
None
Explanation:

An empty list remains empty.

Loading...
Input
1 → 2 → 3 → null
Output
3 → 2 → 1 → null

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!