1 class Solution { 2 public: 3 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { 4 ListNode preheader(-1), *curr=&preheader; 5 int carry=0; 6 while(l1||l2||carry) { 7 curr->next = new ListNode(((l1?l1->val:0)+(l2?l2->val:0)+carry)%10); 8 curr = curr->next; 9 carry = ((l1?l1->val:0)+(l2?l2->val:0)+carry)/10; 10 l1?l1=l1->next:0; 11 l2?l2=l2->next:0; 12 } 13 return preheader.next; 14 } 15 };