# Reverse Linked List LeetCode Solution

Here, We see Reverse Linked List problem Solution. This Leetcode problem is done in many programming languages like C++, Java, JavaScript, Python, etc., with different approaches.

# List of all LeetCode Solution

## Problem Statement

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

```Example 1: (fig-1)
Output: [5,4,3,2,1]```
```Example 2: (fig-2)
Output: [2,1]

Example 3:
Output: []```

## Reverse Linked List Leetcode Solution C++

``````class Solution {
public:
ListNode *pre = new ListNode(0), *cur = head;
while (cur && cur -> next) {
ListNode* temp = pre -> next;
pre -> next = cur -> next;
cur -> next = cur -> next -> next;
pre -> next -> next = temp;
}
return pre -> next;
}
};
```Code language: C++ (cpp)```

## Reverse Linked List Leetcode Solution Java

``````class Solution {
}
}
```Code language: Java (java)```

## Reverse Linked List Leetcode Solution JavaScript

``````var reverseList = function(head) {
let [prev, current] = [null, head]
while(current) {
[current.next, prev, current] = [prev, current, current.next]
}
return prev
};
```Code language: JavaScript (javascript)```

## Reverse Linked List Leetcode Solution Python

``````class Solution(object):
prev = None

while curr:
next = curr.next
curr.next = prev
prev = curr
curr = next
return prev
```Code language: Python (python)```
Scroll to Top