Add Two Numbers
Medium
LC #2
dummy headmathcarryNot attempted yet
Two non-negative integers are stored as linked lists of digits in reverse order: the head holds the ones digit. Return their sum as a list in the same format.
Neither number has leading zeros, except the number 0 itself.
Example 1
Input: l1 = [9,4,2], l2 = [5,6]
Output: [4,1,3]
249 + 65 = 314
Example 2
Input: l1 = [0], l2 = [0]
Output: [0]
Example 3
Input: l1 = [9,9,9], l2 = [1]
Output: [0,0,0,1]
999 + 1 = 1000
Constraints
- 1 ≤ nodes in each list ≤ 2 · 10⁴
- 0 ≤ Node.val ≤ 9