[Python] Two pointers approch, explained
Two passes solution is straightforward. For one pass solution we use the idea of 2 iterators, let one of them start at the beginning, another at index n, then w
Two passes solution is straightforward. For one pass solution we use the idea of `2` iterators, let one of them start at the beginning, another at index `n`, then when the second one is finished, the first one will be on the right place.\n\n#### Complexity\nTime complexity is `O(L)`, more precisely we make `2L-n` steps, where `L` is length of list, space complexity is `O(1)`. So it the end it is exactly the same as staightforward two passes solution. So, if you meet this problem in real interview, you can just explain two pass solution, and when interviewer say can you do better: explain him that another one pass solution in fact is exaclty the same time and space.\n\n#### Code\n```\nclass Solution:\n    def removeNthFromEnd(self, head, n):\n        dummy = ListNode(0)\n        dummy.next = head\n        P1, P2 = dummy, dummy\n        for _ in range(n): P2 = P2.next\n        \n        while P2.next:\n            P1 = P1.next\n            P2 = P2.next\n            \n        P1.next = P1.next.next\n        \n        return dummy.next\n```\n\nIf you have any questions, feel free to ask. If you like solution and explanations, please **Upvote!**
['Two Pointers']