Leetcode--Add two number

时间:2021-06-21 07:06:08

地址:https://leetcode.com/problems/add-two-numbers/

代码:

class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
               ListNode *head;
        ListNode *current = );
        head = current;
        ;
        ) {
            if (l1 != NULL && l2 != NULL) {
                current->val = l1->val + l2->val + temp;
                l1 = l1->next;
                l2 = l2->next;
            } else if (l1 == NULL && l2 == NULL)
                current->val =  + temp;
            else if (l1 == NULL) {
                current->val = l2->val + temp;
                l2 = l2->next;
            } else if (l2 == NULL) {
                current->val = l1->val + temp;
                l1 = l1->next;
            }
            temp = ;
            ) {
                current->val %= ;
                temp = ;
            }
            ) {
                current->next = );
                current = current->next;
            }
        }
        return head;
    }
};