Loading
Loading
A processing chain is stored as a singly linked list, each node pointing to the next stage.
Reverse the chain and return the new head.
1 → 2 → 3 → nullprev=null, node=1save 2, point 1 back at nullprev=1, node=2save 3, point 2 back at 1prev=2, node=3save null, point 3 back at 2node=nullprev is the new head3 → 2 → 1 → nullSign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
Example 3
An empty chain reverses to an empty chain.