Problem :

https://leetcode.com/problems/flatten-nested-list-iterator/


My Solution :

class NestedIterator(object):

def __init__(self, nestedList):
def generator(nestedList):
for item in nestedList:
if item.isInteger():
yield item.getInteger()
else:
for yielded in generator(item.getList()):
yield yielded

self.generator = generator(nestedList)

def next(self):
return self.value

def hasNext(self):
self.value = next(self.generator, None)
return self.value is not None