Skip to content
6
0
:
0
0

Undo Recent Events

Easy

Linked List

In "Undo Recent Events", a singly linked sequence is represented as an array in input order.

Return the sequence in reversed order as if the linked list pointers were fully reversed.

Example 1

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

For input head = [2,3,4], reversing the node direction makes the values appear in reverse order, so the output is [4,3,2]. Therefore, return [4,3,2].

Example 2

Input:head = [4,5]
Output:[5,4]

For input head = [4,5], reversing the node direction makes the values appear in reverse order, so the output is [5,4]. Therefore, return [5,4].

Constraints

  • 0 <= head.length <= 5000
  • -5000 <= head[i] <= 5000
solution.js
Loading...

Test Cases (2)

Test Case 1
Input:
[2,3,4]
Expected Output:
[4,3,2]
Test Case 2
Input:
[4,5]
Expected Output:
[5,4]