Add numbers stored as digit lists
Two non-negative integers are stored as singly linked lists of digits, least significant digit first: 2 → 4 → 3 is 342. Write add_lists(a, b): return the first node of a list in the same format that holds their sum, so 2 → 4 → 3 plus 5 → 6 → 4 gives 7 → 0 → 8 (342 + 465 = 807). Neither list is empty, the lists may differ in length, and the last digit (the most significant) is never 0 except in the number 0 itself. Each ListNode has val and next.
Add digit by digit with a carry, as on paper, instead of turning the lists into Python integers. You may create new nodes for the result.
The tests call the provided run_add_lists(a_digits, b_digits), which builds both lists and returns the digits of the list you return.
Examples
run_add_lists([2,4,3], [5,6,4])→[7,0,8]run_add_lists([9,9,9,9,9,9,9], [9,9,9,9])→[8,9,9,9,0,0,0,1]run_add_lists([0], [0])→[0]