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;inext; + while(fast->next!=NULL){ + fast = fast->next; + slow = slow->next; + } + slow->next = slow->next->next; + return dummy->next; + } +};