/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* @param head ListNode类
* @param n int整型
* @return ListNode类
*/
function removeNthFromEnd( head , n ) {
// write code here
if(!head)return null
let quick = head;
let slow = head;
for(let i = 0;i<n;i++){
quick = quick.next;
}
//这一步真是太关键了
if(quick == null){
return head.next
}
while(quick.next){
quick = quick.next;
slow = slow.next;
}
slow.next = slow.next.next
return head
}
module.exports = {
removeNthFromEnd : removeNthFromEnd
};