Submission Detail

44 / 44 test cases passed.
Status:

Accepted

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

Accepted Solutions Runtime Distribution

Sorry. We do not have enough accepted submissions to show distribution chart.

Accepted Solutions Memory Distribution

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

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

Invite friends to challenge Reverse Linked List II


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
47
48
49
50
51
52
53
54
55
56
57
58
/**
* 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 reverseBetween(ListNode head, int left, int right) {
ListNode h = head;
if (head.next == null)
return head;
if (head == null)
return null;
// get starting node
ListNode start = new ListNode();
int count = 1;
while (head != null && count < left) {
head = head.next;
count++;
}
start = head;
ListNode n1 = start;
// pairwise swap
int interval = right - left;
while (left < right) {
count = 0;
ListNode i = start;
// travel to opposite end of interval
while (count < interval) {
if (i != null) {
i = i .next;
}
count++;
}
// swap nodes
int temp = n1.val;
n1.val = i.val;
i.val = temp;
interval--;
left++;
right--;
n1 = n1.next;
}
return h;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX