# 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.

## 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)```

#### Trapping Rain Water LeetCode Solution

Given n non-negative integers representing an elevation map where the width of each bar is…

#### Zigzag Conversion LeetCode Solution

The string PAYPALISHIRING is written in a zigzag pattern on a given number of rows…

#### Contains Duplicate III LeetCode Solution

You are given an integer array nums and two integers indexDiff and valueDiff. Find a pair of indices (i, j) such that:…

#### Median of Two Sorted Arrays LeetCode Solution

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time…

#### House Robber LeetCode Solution

Given an integer array nums representing the amount of money of each house, return the…

#### Substring with Concatenation of All Words LeetCode Solution

You are given a string s and an array of strings words. All the strings…
Scroll to Top