题目:https://leetcode.com/problems/add-two-numbers/description/
代码:
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
ListNode head(0), *res = &head;
int c=0;
while(l1||l2||c){
int temp = (l1?l1->val:0) + (l2?l2->val:0)+c;
res->next=new ListNode(temp%10);
c=temp/10;
res=res->next;
l1=l1?l1->next:l1;
l2=l2?l2->next:l2;
}
return head.next;
}
};