FunctionRacerProblemsRace

Add Two Numbers II

MediumLinked listsPython, JavaScript, TypeScript, Java, C++

Lists l1 and l2 each hold the digits of a non-negative number with the most significant digit first (the usual reading order). Add the two numbers and return the sum as a list in the same format, with no leading zeros unless the sum is 0.

Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.

Example 1

l1 [7,2,4,3]
l2 [5,6,4]
returns [7,8,0,7]

7243 + 564 = 7807.

Example 2

l1 [9,9]
l2 [1]
returns [1,0,0]

99 + 1 = 100.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Linked lists problems