We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4241871 commit 14ce9cdCopy full SHA for 14ce9cd
19.js
@@ -0,0 +1,33 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val) {
4
+ * this.val = val;
5
+ * this.next = null;
6
+ * }
7
+ */
8
9
+ * @param {ListNode} head
10
+ * @param {number} n
11
+ * @return {ListNode}
12
13
+var removeNthFromEnd = function(head, n) {
14
+ var temp = head,
15
+ pos = head,
16
+ count = 0;
17
+ while(temp.next !== null){
18
+ temp = temp.next;
19
+ count++;
20
+ if(count === n) break;
21
+ }
22
+ if(count !== n){
23
+ head = head.next;
24
+ return head;
25
26
27
28
+ pos = pos.next;
29
30
+ if(pos.next === null) return null;
31
+ pos.next = pos.next.next;
32
33
+};
0 commit comments