434. Reverse Linked List
0
Easy
Given the head of a singly linked list, reverse the order of the nodes and return the reversed list.
Input Format
The input starts with an integer N, which represents the number of nodes in the linked list. The next line contains N space-separated integers, which are the values of the nodes.
Output Format
Print the reversed linked list as a space-separated sequence of integers.
Example
Input
3
1 2 3
Output
3 2 1
Constraints
The number of nodes in the linked list falls within the range of 0 to 5000, inclusive.
Each node's value is an integer between -5000 and 5000, inclusive.
Each node's value is an integer between -5000 and 5000, inclusive.
Loading...
View Submissions
Console