19.Remove Nth Node From End of List (E)
1.Description(Easy)
Notice
2.Code
ListNode removeNthFromEnd(ListNode head, int n) {
if(head==null || n<=0){
return null;
}
ListNode dummy=new ListNode(0);
dummy.next=head;
ListNode fast=head;
ListNode slow=dummy;
for(int i=0;i<n;i++){
if(fast==null){
return null;
}
fast=fast.next;
}
while(fast!=null){
fast=fast.next;
slow=slow.next;
}
slow.next=slow.next.next;
return dummy.next;
}Last updated