Submission Detail

1568 / 1568 test cases passed.
Status:

Accepted

Runtime: 2 ms
Memory Usage: 43.5 MB
Submitted: 2 weeks, 1 day ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
2
4
6
8
10
12
14
16
18
20
22
20
40
60
80
100
java
You are here!
Your runtime beats 99.15 % of java submissions.
Runtime (ms)
Distribution (%)

0.0
2.5
5.0
7.5
10.0
12.5
15.0
17.5
20.0
50
100
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

40750
41000
41250
41500
41750
42000
42250
42500
42750
43000
43250
43500
2
4
6
8
10
java
You are here!
Your memory usage beats 21.48 % of java submissions.
Memory (KB)
Distribution (%)

41000
41500
42000
42500
43000
43500
5
10
Zoom area by dragging across this chart

Invite friends to challenge Add Two Numbers


Submitted Code: 2 weeks, 1 day 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
59
60
61
62
63
64
65
66
67
/**
* 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 addTwoNumbers(ListNode l1, ListNode l2) {
int count = 0;
int carry = 0;
int t1;
int t2;
if (l1 == null)
t1 = 0;
else
t1 = l1.val;
if (l2 == null)
t2 = 0;
else
t2 = l2.val;
int sum = t1 + t2 + carry;
if (sum > 9)
carry = 1;
else
carry = 0;
ListNode s1 = new ListNode(sum%10);
ListNode prev = s1;
if (l1 != null)
l1 = l1.next;
if (l2 != null)
l2 = l2.next;
while (l1 != null || l2 != null) {
if (l1 == null)
t1 = 0;
else
t1 = l1.val;
if (l2 == null)
t2 = 0;
else
t2 = l2.val;
sum = t1 + t2 + carry;
if (sum > 9)
carry = 1;
else
carry = 0;
ListNode sum_node = new ListNode(sum%10);
prev.next = sum_node;
if (l1 != null)
l1 = l1.next;
if (l2 != null)
l2 = l2.next;
prev = sum_node;
}
if (carry == 1) {
ListNode final_node = new ListNode(1);
prev.next = final_node;
}
return s1;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX