diff --git a/src/remove_nth_node_from_end_of_list.py b/src/remove_nth_node_from_end_of_list.py index e6a5eac..0b95b11 100644 --- a/src/remove_nth_node_from_end_of_list.py +++ b/src/remove_nth_node_from_end_of_list.py @@ -6,15 +6,19 @@ def removeNthFromEnd( self, head: ListNode | None, n: int ) -> ListNode | None: dummy = ListNode(next=head) - slow, fast = dummy, dummy + slow = fast = dummy for _ in range(n): assert fast.next + fast = fast.next while fast.next: - slow = slow.next # type: ignore + assert fast.next and slow.next + fast = fast.next + slow = slow.next - slow.next = slow.next.next # type: ignore + assert slow.next + slow.next = slow.next.next return dummy.next