category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

2 - Add two numbers, Medium

Code ```cpp ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode* head = nullptr; ListNode* tail = head; int carry = 0; while (l1 != nullptr or l2 != nullptr) { int current = 0; if (l1 != nullptr and l2 != nullptr) { current = l1 -> val + l2 -> val + carry; carry = current / 10; current %= 10; } else if (l1 != nullptr) { current = l1 -> val + carry; carry = current / 10; current %= 10; } else { current = l2 -> val + carry; carry = current / 10; current %= 10; } ListNode *temp = new ListNode; temp -> val = current; temp -> next = nullptr; if (head == nullptr) { head = tail = temp; } else { tail -> next = temp; tail = temp; } if (l1 != nullptr) l1 = l1 -> next; if (l2 != nullptr) l2 = l2 -> next; } if (carry) { ListNode *temp = new ListNode; temp -> val = carry; temp -> next = nullptr; tail -> next = temp; tail = temp; } return head; } ```