We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 49a80f8 commit 0b60257Copy full SHA for 0b60257
19. Remove Nth Node From End of List
@@ -0,0 +1,30 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * public class ListNode {
4
+ * int val;
5
+ * ListNode next;
6
+ * ListNode() {}
7
+ * ListNode(int val) { this.val = val; }
8
+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9
+ * }
10
+ */
11
+class Solution {
12
+ public ListNode removeNthFromEnd(ListNode head, int n) {
13
+ ListNode dummy =new ListNode(0);
14
+ dummy.next = head;
15
+ ListNode current = dummy, nth = dummy;
16
+
17
+ for(int i=1;i<=n+1;i++){
18
+ current = current.next;
19
+ }
20
21
+ while(current!=null){
22
23
+ nth = nth.next;
24
25
26
+ nth.next = nth.next.next;
27
28
+ return dummy.next;
29
30
+}
0 commit comments