1、提交错误用例:[9] [9],本机输出[8,1],提交后输出[9,1]
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2)
{
static int c = 0;
struct ListNode *l3 = (struct ListNode *)malloc(sizeof(struct ListNode));
struct ListNode *temp = NULL;
memset(l3,0,sizeof(struct ListNode));
if(l1 && l2)
{
c += l1->val + l2->val;
l3->val = c%10;
c = c/10;
printf("c %d\n",c);
if(l1->next && l2->next)
{
l1 = l1->next;
l2 = l2->next;
l3->next = addTwoNumbers(l1,l2);
}
else
{
if(c)
{
struct ListNode *temp = (struct ListNode *)malloc(sizeof(struct ListNode));
memset(temp,0,sizeof(struct ListNode));
temp->val = c;
temp->next = NULL;
l3->next = temp;
}
}
}
printf("===%d\n",l3->val);
return l3;
}