```
def __init__(self, nestedList):
"""
Initialize your data structure here.
:type nestedList: List[NestedInteger]
"""
self.stack = nestedList[::-1]
def next(self):
"""
:rtype: int
"""
if self.hasNext():
return self.stack.pop().getInteger()
def hasNext(self):
"""
:rtype: bool
"""
while self.stack:
curr = self.stack.pop()
if curr.isInteger():
self.stack.append(curr)
return True
self.stack += curr.getList()[::-1]
return False
```