# Why I got wrong answer?

• My code of "Add Two Numbers " as follows,
for the first case
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

my ouput on the OJ is 0->7->0
but on my compilation is 7->0->8.

/**

• struct ListNode {
• ``````int val;
``````
• ``````struct ListNode *next;
``````
• };
*/
typedef struct ListNode Node, *PNode;

{
return 1;
}
else {
return 0;
}
}

{
}
while(tmp != NULL) {
if(tmp->next != NULL) {
tmpNext = tmp->next;
}
else {
tmpNext = NULL;
}
tmp = tmpNext;
}
}

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
struct ListNode *result = (PNode)malloc(sizeof(Node));
result->next = NULL;
PNode p = result;

``````PNode link1 = reverseLinkList(l1);

PNode tmp;
while(p1!= NULL && p2 != NULL) {
addResult = carry + p1->val + p2->val;
carry = 1;
}
else {
carry = 0;
}
tmp = (PNode)malloc(sizeof(Node));
tmp->next = NULL;
p->next = tmp;
p = p->next;
p1 = p1->next;
p2 = p2->next;
}
while(p1 != NULL) {
carry = 1;
}
else {
carry = 0;
}
tmp = (PNode)malloc(sizeof(Node));
tmp->next = NULL;
p->next = tmp;
p = p->next;
p1 = p1->next;
}
while(p2 != NULL) {
carry = 1;
}
else {
carry = 0;
}
tmp = (PNode)malloc(sizeof(Node));
tmp->next = NULL;
p->next = tmp;
p = p->next;
p2 = p2->next;
}

return result;
``````

}