✅19. C++ Solution || Easy to Understand with Explanation || Conceptual & knowledgable
Knockcat\n\n* Detailed Understanding of each Case.\n* Conceptual Approach.\n* Worth it Approach.\n* C syntax also given.\n\n\nclass Solution {\npublic:\n    Lis
**Knockcat**\n```\n* Detailed Understanding of each Case.\n* Conceptual Approach.\n* Worth it Approach.\n* C syntax also given.\n```\n```\nclass Solution {\npublic:\n    ListNode* removeNthFromEnd(ListNode* head, int n) {\n        ListNode *temp = new ListNode;                 //Allocating Memory For New Node using new Keyword;\n        temp = head;                                   //Initializing it to head;\n        int cnt = 0;\n        \n        while(temp != NULL)\n        {\n            cnt++;\n            temp = temp->next;\n        }\n        \n        if(cnt == 0)\n            return head;\n        \n        int cnt_first = (cnt - n) + 1;               //position of nth node from head\n        \n        head = Delete(head , cnt_first , cnt);       //function Delete to Delete the Node\n        \n        return head;\n    }\n    \n    ListNode *Delete(ListNode *head, int  pos,int cnt)\n    {\n        if(head == NULL)\n            return head;\n        \n        //If Deleted Node happen to be first Node\n        else if(head != NULL && pos == 1)\n        {\n            ListNode *curr = new ListNode;      //Allocating memory using keyword new & then initializing node to head\n            curr = head;\n            // ListNode *curr = head;           //C syntax\n            head = head -> next;\n            // free(curr);                      //C syntax\n            delete curr;\n            curr = NULL;\n        }\n        \n        //If Deleted Node happen to be Last Node\n        else if(head != NULL && pos == cnt )    \n        {\n            ListNode *curr = new ListNode;      //Allocating memory using keyword new & then initializing node to head;\n            curr = head;\n            while (curr->next->next != NULL)\n            {\n                curr = curr->next;\n            }\n            ListNode *temp = new ListNode;\n            temp = curr->next;\n            // free(temp);                      //C syntax\n            delete temp;\n            temp = NULL;\n            curr->next = NULL;\n        }\n        \n        else if(cnt < pos || cnt < 1)\n        {\n            // cout<<"Not a valid position"<<end;\n        }\n        \n        //If Deleted Node happen to be the Intermediate Node\n        else\n        {\n            ListNode *curr = new ListNode;      //Allocating memory using keyword new & then initializing node to head;\n            curr = head;\n            ListNode *prev = new ListNode;\n            prev = head;\n            // ListNode *prev = NULL, *curr = head; //C syntax\n            while(pos > 1)\n            {\n                prev = curr;\n                curr = curr -> next;\n                pos--;\n            }\n            prev -> next = curr -> next;\n            // free(curr);                      //C syntax\n            delete curr;\n            curr = NULL;\n        }\n        \n        return head;\n    }\n};\n```
['Linked List', 'C']