FunctionRacerProblemsRace

Add Two Numbers

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

Lists l1 and l2 each hold the digits of a non-negative number in reverse order: the head is the ones digit, the next node is the tens digit, and so on. Add the two numbers and return the sum in the same reversed-digit list format.

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 [2,4,3]
l2 [5,6,4]
returns [7,0,8]

342 + 465 = 807, stored as 7, 0, 8.

Example 2

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

99 + 1 = 100, stored as 0, 0, 1.

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