Decode Count Value Pairs
The list has an even number of nodes and is read two at a time as (count, value). Each pair stands for count copies of value. Return the full list with all the copies, in order. For 2 -> 7 -> 1 -> 5 the answer is 7 -> 7 -> 5. A count of 0 adds nothing. The list is passed in as head.
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
head [2,7,1,5]
returns [7,7,5]
Two 7s, then one 5.
Example 2
head [0,9,3,1]
returns [1,1,1]
Zero 9s, three 1s.
Constraints
0 <= number of nodes <= 40, and the number is even- Every count is between 0 and 5
-100 <= value <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.