Chaturmind
LearnDSASystem DesignBlogPremium
Sign inGet started
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML

Company

  • Blog
  • Premium
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.

DSA›Linked Lists›Reverse Linked List
EasyLinked Lists

Reverse Linked List

linked-listrecursion

Problem

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

Examples

Example 1

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

Hints

Hint 1

Use three pointers: prev, curr, next.

Solutions

public ListNode reverseList(ListNode head) {
    ListNode prev = null;
    ListNode curr = head;
    while (curr != null) {
        ListNode next = curr.next; // save next
        curr.next = prev;          // reverse pointer
        prev = curr;               // advance prev
        curr = next;               // advance curr
    }
    return prev; // prev is the new head
}
Java

Time: O(n) · Space: O(1)