Add Two Numbers Stored in Reverse Order

Implement addTwoNumbers

You're given two non-empty linked lists, l1 and l2, each representing a non-negative integer with its digits stored in reverse order — the head node holds the ones digit. Add the two numbers and return the sum as a linked list in the same reverse-order format. Because the least significant digit already comes first in both lists, this maps almost directly onto how addition works by hand: process one digit position at a time, track a carryCarryWhenever two digits (plus any incoming carry) sum to 10 or more, only the ones digit is kept at that position — the tens digit "carries" forward to be added into the next position over. for anything that overflows past 9, and keep going until both lists — and the carry — are exhausted.

Example 1:

Input: l1 = [2,4,3], l2 = [5,6,4]

Output: [7,0,8]

Example 2:

Input: l1 = [0], l2 = [0]

Output: [0]

Example 3:

Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]

Output: [8,9,9,9,0,0,0,1]

+ 5 hidden test cases run on Submit.

Constraints:

  • 1 ≤ number of nodes in l1, l2 ≤ 100
  • 0 ≤ node value ≤ 9
  • Each list represents a non-negative integer with digits stored in reverse order — the head is the ones digit — and has no leading zeros, except the number 0 itself

l1 =

[2, 4, 3]

l2 =

[5, 6, 4]