Problem
You are given an immutable linked list, print out all values of each node in reverse with the help of the following interface:ImmutableListNode: An interface of immutable linked list, you are given the head of the list.
ImmutableListNode directly):
ImmutableListNode.printValue(): Print value of the current node.ImmutableListNode.getNext(): Return the next node.
print_value() call records the node value, and the recorded values are compared with the expected reversed sequence.
Examples
Constraints
- The length of the linked list is between
[1, 1000]. - The value of each node in the linked list is between
[-1000, 1000].
- Could you solve this problem in constant space complexity?
- Could you solve this problem in linear time complexity and less than linear space complexity?