CT009

Reverse the Spirit Chain

EasyAcceptance: 0.0%

The shamans of Codetikki weave spirit-chains where each link points to the next. A young shaman must learn to reverse the chain in place. Given the head of a singly linked list, reverse it in-place. The input is given as space-separated values representing the linked list nodes in order. Output the reversed list as space-separated values.

Example 1:

Input: 5 1 2 3 4 5
Output: 5 4 3 2 1

Example 2:

Input: 3 15 42 7
Output: 7 42 15

Constraints:

0 <= n <= 10^4 -10^3 <= node value <= 10^3

Tags:

linked-list recursion
Loading...
Test Cases:No test cases
No test cases available.