参考上一题的快慢指针

遍历慢指针的注意注意保存前驱节点

 function removeNthFromEnd( head ,  n ) {
  let fast = head,slow = head;
  for(let i=0; i<n; i++)  fast = fast.next;
  if(fast == null)  return head.next;
  
  let pre;
  while(fast!=null){
    fast = fast.next;
    pre = slow;
    slow = slow.next;
  }
  pre.next = slow.next;
  return head;
}