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.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Input: l1 = [0], l2 = [0]
Output: [0]
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
Output: [8,9,9,9,0,0,0,1]
[1, 100].0 <= Node.val <= 9The naive approach involves iterating through both linked lists simultaneously, adding the digits, and managing the carry.
dummyHead with value 0. This will help to easily return the head of the new linked list.current pointer to point at dummyHead.carry to 0.null to represent value 0) and the carry.0 or 1).sum % 10 and attach it to current.current.dummyHead.next.m and n are the lengths of the two lists. We iterate through both lists once.