FunctionRacerProblemsRace

Build a Range List

BeginnerLinked listsPython, JavaScript, TypeScript, Java, C++

Build a linked list that holds the same numbers as Python's range(start, stop, step): begin at start and keep adding step while the value has not reached stop (smaller than stop for a positive step, larger than stop for a negative step). Return the head, or None if there are no numbers.

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

start 2
stop 7
step 2
returns [2,4,6]

2, 4, 6.

Example 2

start 5
stop 0
step -2
returns [5,3,1]

5, 3, 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