ListNoderemoveNthFromEnd(ListNode head,int n) {if (head ==null) {returnnull; }ListNode dummy =newListNode(-1);dummy.next= head;ListNode slow = dummy; // one before the node get deletedListNode fast = head;// move fast n step earlier than slowwhile (n >0) { fast =fast.next; n--; }// move them together, while fast == null, slow will be on the nth nodewhile (fast !=null) { fast =fast.next; slow =slow.next; }slow.next=slow.next.next;returndummy.next;}