From 3dbf3b744c70068de02d04df5a2e48c484c62388 Mon Sep 17 00:00:00 2001
From: Ashutosh <106524453+Ashutosh741@users.noreply.github.com>
Date: Thu, 13 Oct 2022 18:15:23 +0530
Subject: [PATCH] Create Remove Nth Node From End of List.cpp
---
.../Remove Nth Node From End of List.cpp | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 CPP/LinkedList/Remove Nth Node From End of List.cpp
diff --git a/CPP/LinkedList/Remove Nth Node From End of List.cpp b/CPP/LinkedList/Remove Nth Node From End of List.cpp
new file mode 100644
index 00000000..6ae25beb
--- /dev/null
+++ b/CPP/LinkedList/Remove Nth Node From End of List.cpp
@@ -0,0 +1,16 @@
+class Solution {
+public:
+ ListNode* removeNthFromEnd(ListNode* head, int n) {
+ ListNode *dummy = new ListNode;
+ dummy->next = head;
+ ListNode*fast = dummy;
+ ListNode*slow = dummy;
+ for(int i=0;i<n;i++)fast = fast->next;
+ while(fast->next!=NULL){
+ fast = fast->next;
+ slow = slow->next;
+ }
+ slow->next = slow->next->next;
+ return dummy->next;
+ }
+};