Implement an algorithm to find the nth to last element of a singly linked list.
This was fairly easy once you figure out that you need two LLNODEs. You send the first node ahead n nodes from the head. Then you move the first node (starting n ahead) and the second node (starting at the head), move them forward one node at a time. When the first node hits the end, that means the second node is at the Nth to Last.
No comments:
Post a Comment