Leetcode - Add Two Numbers - Two Solutions
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.
Full problem here.
Solution 1. Based on this solution
var addTwoNumbers = function(l1, l2) {
const head = new ListNode(0)
let firstNode = l1
let secondNode = l2
let currentNode = head
let carry = 0
while (firstNode || secondNode || carry) {
const firstValue = firstNode?.val || 0
const secondValue = secondNode?.val || 0