[Python] - Two Pointer - Clean & Simple - O(n) Solution
\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n
\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:\n        dummy = ListNode()\n        dummy.next = head\n\n        pnt1, pnt2 = dummy, head\n        for _ in range(n):\n            pnt2 = pnt2.next\n\n        while pnt2:\n            pnt1, pnt2 = pnt1.next, pnt2.next\n        \n        pnt1.next = pnt1.next.next\n        return dummy.next\n\n```\n\n## Easy To Understand Solution :\n```\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:\n        trav = head\n        size = 0\n        while True:\n            size += 1\n            trav = trav.next\n            if trav == None:\n                break\n        \n        if size == 1:\n            return None\n        \n        if size == n:\n            return head.next\n        \n        \n        trav = head\n        while size != n + 1:# or you can write size - n - 1 != 0 :\n            trav = trav.next\n            n+=1\n        \n        trav.next = trav.next.next\n        return head\n```
['Linked List', 'Two Pointers', 'Python3']