Simple C++ solution, Very Easy


#1
ListNode* Solution::addTwoNumbers(ListNode* l1, ListNode* l2) {
    if(!l1) return l2;
    if(!l2) return l1;
    int sum=0;
    int carry=0;
    ListNode* l3 = new ListNode(-1);
    ListNode* head = l3;
    while(l1 || l2 || carry){
        sum = (l1?l1->val:0)+(l2?l2->val:0)+carry;
        carry = sum/10;
        l1 = l1?l1->next : NULL;
        l2 = l2?l2->next : NULL;
        l3->next = new ListNode(sum%10);
        l3 = l3->next;
    }
    return head->next;
}

#2

If this solution was a lady, I would marry her xD
Such a small and elegant solution!