Skip to content

Commit

Permalink
Merge pull request #620 from Bluetoothworks/addcode
Browse files Browse the repository at this point in the history
leetcode soln of "remove Nth node from the End"
  • Loading branch information
gantavyamalviya authored Oct 5, 2022
2 parents 1bce71b + c61dde1 commit ddf0258
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Leetcode-solutions/Binary-search/RemoveNthNodeFromEndLL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
int c=0;
if(!head) return head;
ListNode* run=new ListNode(0), *dup=run;
run->next=head;
ListNode* k=head;
while(k!=NULL)
{
if(c==n)
{
run=run->next;
}
else
c++;
k=k->next;
}
ListNode* temp=run->next;
run->next=run->next->next;

return dup->next;
}
};

0 comments on commit ddf0258

Please sign in to comment.