class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
// by: huahuajiang
ListNode dummy(0); // 最好不要new了, 不然还得释放
ListNode* tail = &dummy;
int sum = 0;
while(l1 || l2 || sum)
{
sum += (l1 ? l1->val : 0) + (l2 ? l2->val : 0);
l1 = l1 ? l1->next : nullptr;
l2 = l2 ? l2->next : nullptr;
tail->next = new ListNode(sum % 10);
sum /= 10;
tail = tail->next;
}
return dummy.next;
}
}