Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

This is the solution to leetcode problem 19 remove nth node from end of list in python #543

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions remove_nth_node_from_end_of_list.py
Original file line number Diff line number Diff line change
@@ -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