The title

Delete the NTH digit from the list

Chestnuts are as follows:

Input: {val: 1, next: {2, val: next: {val: 3, the next: {val: 4, next: {val: 5, next: null}}}}} 2 output: {val:1,next:{val:2,next:{val:3,next:{val:5,next:null}}}}

Examples are as follows:

/** * @param {ListNode} head * @param {number} n * @return {ListNode} * */ var removeNthFromEnd = function(head, n) {let re = []; while(head){ re.push(head); head = head.next; } if(n == re.length){ return re[1] || null; }else if(n == 1){ re[re.length - 2].next = null; return re[0] || null; }else{ re[re.length - n -1 ].next = re[re.length - n + 1]; return re[0]; }};Copy the code