#19
Remove Nth Node From End of List
medium· Linked Listruns: 0Given the head of a linked list, remove the nth node from the end of the list and return the modified head.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 388
class Solution:
def removeNthFromEnd(
self, head: ListNode | None, n: int
) -> ListNode | None:
dummy = ListNode(0, head)
left = dummy
right = head
for _ in range(n):
right = right.next
while right:
left = left.next
right = right.next
left.next = left.next.next
return dummy.next
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.