快慢指针 复杂度:O(n);O(1)
* 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 fast = head,slow = head
for(let i = 0;i <= n - 1 ;i++){
fast = fast.next
}
if(!fast){
return head.next
}
while(fast.next){
fast = fast.next
slow = slow.next
}
slow.next = slow.next.next
return head
}
module.exports = {
removeNthFromEnd : removeNthFromEnd
};