链表
class Solution {
public:ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int add = 0;
ListNode *head=NULL,*cur;
while(l1!=NULL||l2!=NULL||add!=0){
if(l1!=NULL){
add += l1->val;
l1 = l1->next;
}
if(l2!=NULL){
add += l2->val;
l2 = l2->next;
}
if(head==NULL){
head = new ListNode(add%10);
add /= 10;
cur = head;
}
else{
cur->next = new ListNode(add%10);
add /= 10;
cur = cur->next;
}
}
return head;
}
};