class NestedIterator:
def __init__(self, nestedList: [NestedInteger]):
self.queue = collections.deque()
self.flat(nestedList)
def next(self) -> int:
return self.queue.popleft()
def hasNext(self) -> bool:
return self.queue
def flat(self, nestedList):
for n in nestedList:
if not n.isInteger():
self.flat(n.getList())
else:
self.queue.append(n.getInteger())