Add Two Numbers II

Medium

Company Tags

You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. For example, 123 is represented as 1 -> 2-> 3. Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example 1:

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

Output: [5,7,9]

Explanation: 123 + 456 = 579

Example 2:

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

Output: [9,9,6]

Explanation: 99 + 897 = 996

Constraints:

  • 1 <= l1.length, l2.length <= 100
  • 0 <= Node.val <= 9
  • It is guaranteed that the list represents a number that does not have leading zeros.

Follow up: Could you solve it without reversing the input lists?



Company Tags

Please upgrade to NeetCode Pro to view company tags.

l1 =

l2 =