Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 2 KBi |
#2 |
Correcto
|
0.005 s | 2 KBi |
#3 |
Correcto
|
0.005 s | 1 KBi |
#4 |
Correcto
|
0.004 s | 2 KBi |
#5 |
Correcto
|
0.006 s | 1 KBi |
#6 |
Correcto
|
0.005 s | 1 KBi |
#7 |
Correcto
|
0.005 s | 1 KBi |
#8 |
Correcto
|
0.004 s | 1 KBi |
#9 |
Correcto
|
0.006 s | 1 KBi |
#10 |
Correcto
|
0.007 s | 1 KBi |
#11 |
Correcto
|
0.007 s | 1 KBi |
#12 |
Correcto
|
0.006 s | 1 KBi |
#13 |
Correcto
|
0.005 s | 1 KBi |
#14 |
Correcto
|
0.006 s | 2 KBi |
#15 |
Correcto
|
0.006 s | 1 KBi |
#16 |
Correcto
|
0.005 s | 1 KBi |
#17 |
Correcto
|
0.006 s | 1 KBi |
#18 |
Correcto
|
0.005 s | 2 KBi |
#19 |
Correcto
|
0.005 s | 1 KBi |
#20 |
Correcto
|
0.005 s | 1 KBi |
#21 |
Correcto
|
0.006 s | 1 KBi |
#22 |
Correcto
|
0.004 s | 2 KBi |
#23 |
Correcto
|
0.005 s | 1 KBi |
#24 |
Correcto
|
0.007 s | 2 KBi |
#25 |
Correcto
|
0.005 s | 1 KBi |
#26 |
Correcto
|
0.006 s | 1 KBi |
#27 |
Correcto
|
0.005 s | 2 KBi |
#28 |
Correcto
|
0.005 s | 1 KBi |
#29 |
Correcto
|
0.005 s | 1 KBi |
#30 |
Correcto
|
0.004 s | 1 KBi |
#31 |
Correcto
|
0.006 s | 1 KBi |
#32 |
Correcto
|
0.006 s | 1 KBi |
#33 |
Correcto
|
0.005 s | 2 KBi |
#34 |
Correcto
|
0.005 s | 1 KBi |
#35 |
Correcto
|
0.006 s | 2 KBi |
#36 |
Correcto
|
0.011 s | 3 KBi |
#37 |
Correcto
|
0.01 s | 4 KBi |
#38 |
Correcto
|
0.011 s | 3 KBi |
#39 |
Correcto
|
0.008 s | 3 KBi |
#40 |
Correcto
|
0.011 s | 3 KBi |
#41 |
Correcto
|
0.01 s | 3 KBi |
#42 |
Correcto
|
0.011 s | 3 KBi |
#include <iostream> #include <string> using namespace std; struct ListNode { int val; ListNode *next; ListNode() : val(0), next(nullptr) {} ListNode(int x) : val(x), next(nullptr) {} ListNode(int x, ListNode *next) : val(x), next(next) {} }; ListNode* add(ListNode* l1, ListNode* l2, int carry) { if (!l1 and !l2 and carry == 0) { return l1; } int sum = (l1 ? l1->val : 0) + (l2 ? l2->val : 0) + carry; carry = 0; if (sum > 9) { sum -= 10; carry = 1; } return new ListNode(sum, add(l1 ? l1->next : l1, l2 ? l2->next : l2, carry)); } ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { return add(l1, l2, 0); } void printList(ListNode *l1) { if (l1) { printList(l1->next); cout << l1->val; } } int main() { string numberStr; cin >> numberStr; ListNode *number = nullptr; for (char c : numberStr) { number = new ListNode(c - '0', number); } cin >> numberStr; ListNode *number2 = nullptr; for (char c : numberStr) { number2 = new ListNode(c - '0', number2); } auto sol = addTwoNumbers(number, number2); printList(sol); return 0; }