How to do this
Leetcode linked list doubt
Reference Code
Plz explain your code and tell how its working
iterator has 2 main functions
- next() => it gives the next element
- 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