Question: 1. Given the head of a linked list, remove the nth node from the end the list and return its head. Follow up: Could you

1. Given the head of a linked list, remove the nth node from the end the list and return its head. Follow up: Could you do this in one pass? The following is part of the code. You should try to design a main method to test the program and submit a runnable and complete program. ** * /** * Definition for singly-linked list. public class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next } */ class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { * * } } Examples: Input: head = [1,2,3,4,5), n = 2 Output: [1,2,3,5] Input: head = [1], n = 1 Output: ()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
