One-pass simple C# solution w/ comments and explanation
Here\'s a one-pass solution with the following algorithm:\n1. Create a dummy node and let the 2 pointers, fast and slow point to that node. Dummy nodes make thi
Here\'s a one-pass solution with the following algorithm:\n1. Create a dummy node and let the 2 pointers, `fast` and `slow` point to that node. Dummy nodes make things easier, especially when we delete the **first node/head**.\n2. Position `fast` so that the gap between them is `n`\n3. To position `slow` just **behind/before the node-to-delete**, move both pointers until `fast.next` is `null` \n4. After the pointers are positioned where they should, delete the node by pointing `slow.next` to `slow.next.next`\n5. Return the head via `dummy.next`\n\n**Implementation**\n\n```\npublic ListNode RemoveNthFromEnd(ListNode head, int n) {\n\tListNode dummy = new(0, head); // Create a dummy node\n\tListNode slow = dummy, fast = dummy;\n\n\t// Gap of fast and slow is n\n\tfor (int i = 0; i < n; i++) {\n\t\tfast = fast.next;\n\t}\n\n\t// Move slow to the node behind the node to delete\n\twhile (fast?.next != null) {\n\t\tslow = slow.next;\n\t\tfast = fast.next;\n\t}\n\n\t\t\t// Delete the node\n\tslow.next = slow.next.next;\n\n\treturn dummy.next;\n}\n```
['Two Pointers', 'C#']