Add Two Numbers as Lists Time : Space : 1234567891011121314151617181920212223242526272829303132333435363738394041/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ListNode* Solution::addTwoNumbers(ListNode* A, ListNode* B) { ListNode* dummy = new ListNode(-1); ListNode* runner = dummy; int carry = 0; while(A and B) { int sum = A->val + B->val + carry; carry = sum / 10; runner->next = new ListNode(sum%10); runner = runner->next; A = A->next; B = B->next; } while(A) { int sum = A->val + carry; carry = sum / 10; runner->next = new ListNode(sum%10); runner = runner->next; A = A->next; } while(B) { int sum = B->val + carry; carry = sum / 10; runner->next = new ListNode(sum%10); runner = runner->next; B = B->next; } if(carry) runner->next = new ListNode(carry); return dummy->next;}