Skip to content
6
0
:
0
0

Rollback Commit Chain

Easy

Linked List

In "Rollback Commit Chain", 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 = [9,10,11,12,13,14]
Output:[14,13,12,11,10,9]

For input head = [9,10,11,12,13,14], reversing the node direction makes the values appear in reverse order, so the output is [14,13,12,11,10,9]. Therefore, return [14,13,12,11,10,9].

Example 2

Input:head = [18,19,20]
Output:[20,19,18]

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

Constraints

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

Test Cases (2)

Test Case 1
Input:
[9,10,11,12,13,14]
Expected Output:
[14,13,12,11,10,9]
Test Case 2
Input:
[18,19,20]
Expected Output:
[20,19,18]