Super Easy Solution in C++


#1

ListNode* Solution::addTwoNumbers(ListNode* A, ListNode* B){
ListNode *head=nullptr, temp=nullptr;
int c=0, v1, v2, count=0, s=0;
while(A || B){
if(A){
v1 = A->val;
A = A->next;
}
else{
v1 = 0;
}
if(B){
v2 = B->val;
B = B->next;
}
else{
v2 = 0;
}
s = v1+v2+c;
c = (s-(s%10))/10;
s = s-10
c;
if(!count){
head = new ListNode(s);
temp = head;
}
else{
temp->next = new ListNode(s);
temp = temp->next;
}
count++;
}
if©{
temp->next = new ListNode©;
}
return head;
}