Skip to content

Instantly share code, notes, and snippets.

@gaohao
Created December 11, 2012 05:57
Show Gist options
  • Save gaohao/4256219 to your computer and use it in GitHub Desktop.
Save gaohao/4256219 to your computer and use it in GitHub Desktop.
Delete the nth last element from a singly linked list
1. Have two pointers ptr1 and ptr2 pointing to head of linked list
2. Traverse one pointer say ptr2 to distance n from head
3. Now, traverse both
4. When ptr2 reaches the tail, ptr1 is at distance "n" from the tail of linked list
recursive?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment