Skip to main content

Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

Problems25 / 152
Sign in

Add Two Numbers

MEDIUMLinked ListMath

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

Example 1

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

Example 2

Input:  l1 = [0], l2 = [0]
Output: [0]
Show hint

Simulate addition digit by digit. Handle carry, and create new nodes for the result. Process both lists until both are exhausted and carry is 0.

Draft saves automatically

Loading editor...

Submit also runs hidden tests
l1 =
[2,4,3]
l2 =
[5,6,4]
Expected
[7,0,8]
Run with your own input (JSON)