Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order (each node contains a single digit). Add the two numbers and return the sum as a linked list. Example: Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807, returned as [7,0,8]. Pattern focus: Dummy Head Node (for result list).

Input Format

l1 = ListNode, l2 = ListNode

Output Format

return ListNode

Constraints

  • 1 <= Number of nodes in each list <= 100
  • 0 <= Node.val <= 9
  • The numbers do not contain leading zeros.

Examples

Example 1:

Input:

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

Output:

[7,0,8]

Explanation:

342 + 465 = 807, represented as [7,0,8].

Example 2:

Input:

l1 = [0]
l2 = [0]

Output:

[0]

Explanation:

0 + 0 = 0.

Loading...
Add Two Numbers - Linked List DSA Problem