Two non-negative integers are stored in linked lists in reverse order (ones digit first). Add the two numbers and return the sum as a linked list in the same format.
Output: [7,0,8]
Explanation: 342 + 465 = 807. Digits stored reversed: 2→4→3 means 342.
Output: [0]
Iterate both lists simultaneously, adding digits plus carry. Create a new node for each sum digit.
- Process digit by digit with carry
- Create result node for each sum % 10
- carry = sum / 10; continue until both lists exhausted and carry == 0
Complexity Analysis:
Time complexity: O(max(m,n))
Space complexity: O(max(m,n)) — result list length