C++ | Diagram | Related Problems
Approach\n- Take two pointers p and q at the head of linked list.\n- Move q pointers by n to the right. Here n = 2.\n- Then move both p and q pointers to right 
**Approach**\n- Take two pointers p and q at the head of linked list.\n- Move q pointers by n to the right. Here n = 2.\n- Then move both p and q pointers to right until q reaches the end.\n- Then change pointer of p node to its next to next node.\n- Don\'t forget to delete the last nth node.\n\n**Digram Representation**\n\n![image](https://assets.leetcode.com/users/images/295d90c6-c36f-48b5-a83a-7028b8640f4e_1664330424.1773272.png)\n\n**C++ Code**\n\n```cpp\nListNode* removeNthFromEnd(ListNode* head, int n) {\n        ListNode *p = head, *q = head;\n        while (n--) q = q->next;\n        if (!q) return head->next;\n        while (q->next) {\n            p = p->next;\n            q = q->next;\n        }\n        ListNode* toDelete = p->next;\n        p->next = p->next->next;\n        delete toDelete;\n        return head;\n}\n```\n\n**Related Problems**\n[1. Linked List Cycle ](https://leetcode.com/problems/linked-list-cycle/)\n[2. Linked List Cycle II ](https://leetcode.com/problems/linked-list-cycle-ii/)\n[3. Reorder List ](https://leetcode.com/problems/reorder-list/)\n[4. Sort List ](https://leetcode.com/problems/sort-list/)\n[5. Swapping Nodes in a Linked List ](https://leetcode.com/problems/swapping-nodes-in-a-linked-list/)
['Linked List', 'Two Pointers', 'C', 'C++']