Submission Detail

55 / 55 test cases passed.
Status:

Accepted

Runtime: 0 ms
Memory Usage: 40.4 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

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

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

Invite friends to challenge Swap Nodes in Pairs


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
/**
* 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 swapPairs(ListNode head) {
if (head == null)
return null;
if (head.next == null)
return head;
ListNode n = head.next;
head.next = n.next;
n.next = head;
ListNode h = n;
ListNode prev = head;
head = head.next;
while (head != null && head.next != null) {
ListNode n2 = head.next;
head.next = n2.next;
n2.next = head;
prev.next = n2;
prev = head;
head = head.next;
}
return h;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX