19. Remove Nth Node From End of List
Description
See: https://leetcode.com/problems/remove-nth-node-from-end-of-list/
Solution
I used the runner technique to solve this problem. I move the runner forward n
times. Then I move both the walker and runner together at the same time. When the runner gets to the end of the linked list, the walker will be at the node prior to the node to be removed. Then it is a matter of updating the walker's next pointer.
My first version was messier than this. I had one while loop and a counter I incremented in it. If the counter was greater than n
then I would move the walker. It worked, but this is tidier.
Last updated