FunctionRacerProblemsRace

Add Lists Position by Position

EasyLinked listsPython, JavaScript, TypeScript, Java, C++

Make a new list where the node at each position holds the sum of the values at that position in l1 and l2. If one list is shorter, treat its missing values as 0, so the result is as long as the longer list.

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 [1,2,3]
l2 [10,20]
returns [11,22,3]

11, 22, then 3 + nothing.

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