# 力扣（LeetCode) -两数相加（C语言）

输入：(2 -> 4 -> 3) + (5 -> 6 -> 4)

/**
* struct ListNode {
*     int val;
*     struct ListNode *next;
* };
*/

struct ListNode *my_linked_list = (struct ListNode *)malloc(sizeof(struct ListNode ));
}

struct ListNode *p;
struct ListNode *q = (struct ListNode *)malloc(sizeof(struct ListNode));
p = obj;
while (p->next)
{
p = p->next;
}
p->next = q;
q->val = val;
q->next = NULL;
}

while (q->next)
{
p = q->next;
q->next = q->next->next;
p = q->next;
}
}

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){
struct ListNode *p = l1;
struct ListNode *q = l2;
int flag = 0;    //进位标志
temp->next = NULL;
while (p && q)
{
temp->val = (p->val + q->val + flag)%10;
flag = ((p->val + q->val + flag)>=10) ? 1 : 0;
p = p->next;
q = q->next;
temp_front = temp;
temp = temp->next;
}
while (p)
{
temp->val = (p->val + flag)%10;
flag = ((p->val + flag)>=10) ? 1 : 0;
p = p->next;
temp_front = temp;
temp = temp->next;
}
while (q)
{
temp->val = (q->val + flag)%10;
flag = ((q->val + flag)>=10) ? 1 : 0;
q = q->next;
temp_front = temp;
temp = temp->next;
}
if (flag == 1)
{
temp->val = 1;
temp->next = NULL;
}
else if (flag == 0)
{
temp_front->next = NULL;
}
}


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客