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