Add Two Numbers (Linked List)

Medium

Description

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order. Add the two numbers and return the sum as a linked list.

Examples

Input:l1 = [2,4,3], l2 = [5,6,4]
Output:[7,0,8]
Explanation:

342 + 465 = 807.

Input:l1 = [5], l2 = [5]
Output:[0,1]
Explanation:

5 + 5 = 10. Since the lists are reversed, this represents adding single digits that produce a carry.

Input:l1 = [1,8], l2 = [0]
Output:[1,8]
Explanation:

81 + 0 = 81. When adding zero to any number, the result is the original number unchanged.

Constraints

  • 1 ≤ list length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!