You are given a list nestedList. Each element of it is either an integer or another list. The inner lists follow the same rule, so they can hold integers and more lists, as deep as you like.
Return all the integers, in order from left to right, as one flat list.
This idea is often used as an iterator with next() and hasNext(). How this judge runs it: there is no iterator class here. Your function gets nestedList as a JSON array and returns the list of values you would get by calling next() again and again until hasNext() is false.
Examples
Example 1:
Input: nestedList = [[2,[3]],4,[[5,6]]]
Output: [2,3,4,5,6]
Explanation: Reading from left to right, we meet 2, 3, 4, 5 and 6.
Example 2:
Input: nestedList = [9,[8,[7,[6]]]]
Output: [9,8,7,6]
Explanation: The lists are nested deeply, but the order is still left to right: 9, 8, 7, 6.
Example 3:
Input: nestedList = [[],7,[[]],8]
Output: [7,8]
Explanation: Empty lists hold no integers, so only 7 and 8 are returned.