Build a Range List
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
-50 <= start, stop <= 50-10 <= step <= 10andstep != 0
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Linked lists problems
- Compare Two ListsBeginner
- Count Distinct ValuesBeginner
- Count Even ValuesBeginner
- Count a Target ValueBeginner
- Count the NodesBeginner
- Count the RisesBeginner
- Differences of NeighborsBeginner
- Everything After a ValueBeginner