Today's problem is a classic. Given a linked list such as the one below, reverse it while optimizing for runtime.
1->5->3->4->9 9->4->3->5->1
Today's problem is a classic. Given a linked list such as the one below, reverse it while optimizing for runtime.
1->5->3->4->9 9->4->3->5->1
Permalink: http://problemotd.com/problem/reverse-linked-list/
Content curated by @MaxBurstein
Comments:
Kevin Benton - 9 years, 11 months ago
reply permalink
Kevin Benton - 9 years, 11 months ago
Sorry, got two copies in there.
reply permalink
Anonymous - 9 years, 11 months ago
A classic Python answer
reply permalink
17 minutes ago - 9 years, 11 months ago
Straightforward O(1) javascript solution:
reply permalink
David - 9 years ago
Treat it as a stack. Pop items from input and push to output. O(n) operation.
Feeling just lazy enough this morning.
reply permalink