Skip to main content
Back to problems
#206
Easy Algorithms

Reverse linked list

Linked List Recursion
80.3% acceptance
Jan 12, 2026
24313
569
Given the head of a singly linked list, reverse the list, and return the reversed list.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
    let mut prev = None;
    let mut curr = head;
    
    while let Some(mut node) = curr {
      curr = node.next.take();
      node.next = prev;
      prev = Some(node);
    }
    prev
  }
}