没有难度
/**
* Definition for singly-linked list.
* 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) {}
* };
*/
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
if(NULL==l1)
return l2;
else if(NULL==l2)
return l1;
ListNode head = ListNode(-1);
ListNode* pergodic = &head;
int jinwei = 0;
while(NULL!=l1 || NULL!=l2 || 0!=jinwei)
{
int sum = jinwei + ((NULL!=l1)?l1->val:0) + ((NULL!=l2)?l2->val:0);
pergodic->next = new ListNode (sum%10);
jinwei = sum/10;
pergodic = pergodic->next;
if(NULL!=l1)
l1 = l1->next;
if(NULL!=l2)
l2 = l2->next;
}
return head.next;
}
};