Reverse a Linked List
Easyjavapythonccppjavascript
Given the head of a singly linked list, reverse all links and print the reversed list.
Input Format
The first line contains an integer N. The second line contains N space-separated integers (empty if N is 0).
Output Format
Print the reversed list from head to tail, separated by single spaces. Print an empty line if the list is empty.
Example 1
Input
4 1 2 3 4
Output
4 3 2 1
Explanation: Every node points to its previous node after reversal.
- 0 <= N <= 100000
- -1000000000 <= value <= 1000000000