Given the head of a linked list, delete the n-th
node from the end of the list and return the updated head.
The linked list is represented by a sequence of ListNode
s, where each node points to the next node in the sequence, or null
if it is the last node.
A ListNode
has the following interface:
interface ListNode {val: number;next: ListNode | null;}
head: ListNode
: Head of the linked list. Examples display each linked list as an array of values within the listn: number
: An integer indicating the position (from the end) of the node to deleteInput: list = [1,2,3,4,5,6], n = 3Output: [1,2,3,5,6]Explanation: The 3rd node from the end is 4. Deleting it results in the list [1, 2, 3, 5, 6].
Input: list = [8], n = 1Output: []Explanation: The list contains only one node, which is the 1st from the end. Deleting it results in an empty list.
Input: list = [9,7], n = 1Output: [9]Explanation: The 1st node from the end is 7. Deleting it results in the list [9].
ListNode.val
<= 1000Given the head of a linked list, delete the n-th
node from the end of the list and return the updated head.
The linked list is represented by a sequence of ListNode
s, where each node points to the next node in the sequence, or null
if it is the last node.
A ListNode
has the following interface:
interface ListNode {val: number;next: ListNode | null;}
head: ListNode
: Head of the linked list. Examples display each linked list as an array of values within the listn: number
: An integer indicating the position (from the end) of the node to deleteInput: list = [1,2,3,4,5,6], n = 3Output: [1,2,3,5,6]Explanation: The 3rd node from the end is 4. Deleting it results in the list [1, 2, 3, 5, 6].
Input: list = [8], n = 1Output: []Explanation: The list contains only one node, which is the 1st from the end. Deleting it results in an empty list.
Input: list = [9,7], n = 1Output: [9]Explanation: The 1st node from the end is 7. Deleting it results in the list [9].
ListNode.val
<= 1000console.log()
statements will appear here.