# My C recursive solution

• My C solution can resolve most cases of customized cases, but by submitting the code, I got struct alignment error, is anybody know why?

``````/**
* struct ListNode {
*     int val;
*     struct ListNode *next;
* };
*/
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2);
struct ListNode* addTwoNumbersExt(int carry, struct ListNode* l1, struct ListNode* l2);
bool checkHasNext(struct ListNode* l1, struct ListNode* l2, int carry);

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
}

struct ListNode* addTwoNumbersExt(int carry, struct ListNode* l1, struct ListNode* l2) {
struct ListNode* lnew = malloc(sizeof(struct ListNode));
if(!l1 && !l2){
if(carry > 0){
lnew->val = carry;
}
return lnew;
}

if(!l1){
lnew->val = l2->val + carry;
}

if(!l2){
lnew->val = l1->val + carry;
}

int tmp;
tmp = l1->val + l2->val + carry;
lnew->val = tmp%10;
if(checkHasNext(l1, l2, tmp/10))

return lnew;
}

bool checkHasNext(struct ListNode* l1, struct ListNode* l2, int carry){
return (l1->next || l2->next || carry!= 0);
}

struct ListNode* addNumbers(struct ListNode* l) {
struct ListNode* lnew = malloc(sizeof(struct ListNode));
if(!l)
return  lnew;

lnew->val = l->val;