LinkedList Print in reverse order
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given a linked list. Print its elements in reverse order.
Definition of a single linked list:
// Java class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } }
// C++ class ListNode { public: int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} };
Implement function PrintReverse that prints the elements of linked list in the reverse order.
// Java void PrintReverse(ListNode head)
// C++ void PrintReverse(ListNode *head)
Example
Function PrintReverse must print in one line elements of a linked list in the reverse order: 3 2 1.
Submissions 3K
Acceptance rate 32%