Python One Pass
Suppose the length of linked list is L, the distance between the node to delete and the tail is |node-tail| = N. Then |node-head| = L-N. So we can use two point
Suppose the length of linked list is L, the distance between the node to delete and the tail is **|node-tail| = N**. Then **|node-head| = L-N**. So we can use two pointers here to get that **L-N**.\n\nPointer **a** first walks N units and there are L-N units left that **a** can walk. Then we have **b** start walking from the head and **a** keep walking simultaneously. \nAfter **L-N** rounds,  **a** will reach the tail and **b** has walked L-N from the head, with a distance N away from the tail. So when **a** reaches the tail, we know the node that **b** is pointing at is what to delete.\n\nIn case the head node is what to delete, we can create a dummy head whose next node is the **head**. Then we have both a and b point at the dummy and eventually return **dummy.next**.\n```\ndef removeNthFromEnd(head, n):\n\ta = b = dummy = ListNode(0)\n\tdummy.next = head\n\tfor _ in range(n): \n\t\ta = a.next\n\twhile a.next: \n\t\ta, b = a.next, b.next\n\tb.next = b.next.next\n\treturn dummy.next\n```\nIt\'s a one pass O(n) time O(1) space solution.
[]