FunctionRacerProblemsRace

Build a List of Digits

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

Given a non-negative integer n, return a linked list of its decimal digits with the most significant digit at the head. For 5071 the list is 5 -> 0 -> 7 -> 1, and for 0 it is the single node 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

n 5071
returns [5,0,7,1]

Digits 5, 0, 7, 1.

Example 2

n 0
returns [0]

Zero is one digit.

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