/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
//虚拟头结点,值不会用到,
//作用:不用特判头结点
auto dummy = new ListNode(-1),cur = dummy;
//进位值
int t = 0;
while(l1 || l2 || t){
if(l1) t+=l1->val,l1 = l1->next;
if(l2) t+=l2->val,l2 = l2->next;
cur = cur->next = new ListNode(t%10);
t/=10;
}
return dummy->next;
}
};