Leetcode linked list doubt

How to do this

Reference Code

Plz explain your code and tell how its working

iterator has 2 main functions

  1. next() => it gives the next element
  2. hasNext() => it tell whether more element present or not

now in this question we have to make an iterator
first we have to flat the list given
so i recursively flatten the list in the function FlattenList()
and then in next() function just provide the next element to iterate
in hasnext return true if i is not at end else false