3 ms·
What about going through the list once, put each node onto a stack, then pop n - 1 elements off the stack, and the nth last element will be on the top of the st
by liamk 17y ago
What about going through the list once, put each node onto a stack, then pop n - 1 elements off the stack, and the nth last element will be on the top of the stack.
Edit: uses too many pointers as cperciva points out below.
- cperciva 17y agoThat uses N additional memory locations, not 3.