diff --git a/remove_nth_node_from_end_of_list.py b/remove_nth_node_from_end_of_list.py new file mode 100644 index 00000000..6b1cf429 --- /dev/null +++ b/remove_nth_node_from_end_of_list.py @@ -0,0 +1,21 @@ +class Solution: + def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]: + + dummy = ListNode(0, head) + left = dummy + right = head + + while n > 0 and right: + right = right.next + n -= 1 + + while right is not None: + left = left.next + right = right.next + + + # deletion code + + left.next = left.next.next + + return dummy.next \ No newline at end of file