Add two numbers (linked list)

Problem Two non-empty linked lists store non-negative integers with digits in REVERSE order (least-significant digit first). Add the two numbers and return the sum as a linked list in the same format.

Input / Output

  • Input: the heads l1, l2 of the two digit lists.
  • Output: the head of the sum list (digits in reverse order).

Constraints

  • Up to 100 digits each — the numbers exceed all primitive types, so digit-by-digit addition is mandatory.

Example

  • 2->4->3 plus 5->6->4 -> 7->0->8 (342 + 465 = 807).
asked …
LeaderboardSalaryAccount