Remove Nth Node From End of List

Given the head of a linked list, remove the nth node from the end of the list and return the head of the modified list.

Constraints

  • The number of nodes in the list is sz.
  • 1 <= sz <= 30
  • 0 <= Node.val <= 100
  • 1 <= n <= sz
Saving… · 10 lines
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next

class Solution:
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:


Console

Click Run to execute sample tests.