Error:
Too many error, I think it is I cannot define the function too well.
The problem is not let you reconstruct the data struct the flatten, it is a iterator to iterate the origin data structure, so it need to get the result on the fly!
So it is like a iterate like DFS, when meet a list, push it on the stack, and record its begin iterator and end iterator at the same time. When begin == end, pop it
Note:
- define hasNext() as the function that when meet the integer then return true, not check if current stack has element.
- define next() just call hasNext(), then return the integer of top element, since in hasNext() we make sure the top iterator always is integer.