C++ || 2-Pointers
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* removeNthFromEnd(ListNode* head, int k) {\n        ListNode *pre_slow, *slow, *fast;\n        pre_slow=NULL;\n        slow=fast=head;\n        \n        for(int i=0;i<k;i++) fast=fast->next;\n        \n        while(fast!=NULL){\n            pre_slow=slow;\n            slow=slow->next;\n            fast=fast->next;\n        }\n        \n        if(pre_slow==NULL){\n            ListNode* new_head = head->next;\n            delete head;\n            return new_head;\n        }\n    \n        pre_slow->next=slow->next;\n        slow->next=NULL;\n        delete slow;\n        \n        return head;\n    }\n};\n```
['C++']