Submission Detail

208 / 208 test cases passed.
Status:

Accepted

Runtime: 0 ms
Memory Usage: 40.3 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
1
2
3
4
5
6
7
8
9
10
11
20
40
60
80
100
java
You are here!
Your runtime beats 100.00 % of java submissions.
Runtime (ms)
Distribution (%)

0
1
2
3
4
5
6
7
8
9
10
11
50
100
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

39400
39600
39800
40000
40200
40400
40600
40800
41000
41200
2.5
5.0
7.5
10.0
12.5
15.0
java
You are here!
Your memory usage beats 98.38 % of java submissions.
Memory (KB)
Distribution (%)

39400
39600
39800
40000
40200
40400
40600
40800
41000
41200
5
10
15
Zoom area by dragging across this chart

Invite friends to challenge Remove Nth Node From End of List


Submitted Code: 0 minutes ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* 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) {
// find size of list
int size = 0;
ListNode h = head;
while (head != null) {
size++;
head = head.next;
}
if (size == 1)
return null;
if (n == size)
return h.next;
head = h;
// navigate to nth node from end
int count = 0;
while (count < size-n-1) {
count++;
h = h.next;
}
// remove nth node from end
if (count == size-1)
h.next = null;
else
h.next = h.next.next;
return head;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX