# LeetCode Reverse Linked List: Recursive VS Iterative Solution

## Overview

LeetCode Reverse Linked List: Recursive solution takes O(N) time and O(N) space while Iterative Solution takes O(N) time and O(1) space.

Reverse a singly linked list. Can you solve it both recursively and iteratively?

## LeetCode Reverse Linked List Recursive and Iterative Solution

LeetCode Reverse Linked List: Recursive solution takes O(N) time and O(N) space while Iterative Solution takes O(N) time and O(1) space. And the following Java code could be accepted by LeetCode OJ to solve this Reverse Linked List problem.

**Note: **

1. be careful about the recursive solution in case of StackOverFlow Exception, and another observation is that the first node and the last node of the reversed linked list is known directly, right?
2. Also take a look at this generalized problem to reverse a linked list from position m to n: LeetCode Reverse Linked List II: One Pass

## Summary

LeetCode Reverse Linked List: Recursive solution takes O(N) time and O(N) space while Iterative Solution takes O(N) time and O(1) space.

Written on July 12, 2015