Reverse Linked List

Linked Lists, problem 1 of 8

Reverse Linked List

Easy

LC #206

in-place reversalpointers

Not attempted yet

You're given the head of a singly linked list. Reverse the list and return the new head.

Example 1

Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]

Example 2

Input: head = [8,3]
Output: [3,8]

Example 3

Input: head = []
Output: []

Constraints

  • 0 ≤ number of nodes ≤ 5 · 10⁴
  • -10⁵ ≤ Node.val ≤ 10⁵

Can you do it in O(1) extra space?

Python

Loading draft…

Test results

7 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 4 hidden

Run examples, then submit all tests.