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.
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.
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.
Sign in to submit, save progress and mark problems as solved. You can still run your code.
Loading editor...
l1 =
[2,4,3]
l2 =
[5,6,4]
Expected
[7,0,8]