/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* @param head ListNode类
* @param n int整型
* @return ListNode类
*/
// function ListNode(x){
// this.val = x;
// this.next = null;
// }
/**
*
* @param head ListNode类
* @param n int整型
* @return ListNode类
*/
function removeNthFromEnd(head, n) {
// write code here
let cur = head;
let node = head;
if (!head) return head;
for (i = 0; i < n; i++) {
cur = cur.next;
if(cur===null) return head.next
}
while (cur.next) {
cur = cur.next;
node = node.next;
}
node.next = node.next.next;
return head;
}
module.exports = {
removeNthFromEnd: removeNthFromEnd,
};