Skip to content

Instantly share code, notes, and snippets.

@shubham1710
Created June 14, 2020 14:31
Show Gist options
  • Save shubham1710/6496fa8133565bf8bb947f03368276d9 to your computer and use it in GitHub Desktop.
Save shubham1710/6496fa8133565bf8bb947f03368276d9 to your computer and use it in GitHub Desktop.
ListNode* removeNthFromEnd(ListNode* head, int n)
{
ListNode** t1 = &head, *t2 = head;
for(int i = 1; i < n; ++i)
{
t2 = t2->next;
}
while(t2->next != NULL)
{
t1 = &((*t1)->next);
t2 = t2->next;
}
*t1 = (*t1)->next;
return head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment