def __init__(self, nestedList): """ Initialize your data structure here. :type nestedList: List[NestedInteger] """ self.stack = [] self.list = nestedList
def next(self): """ :rtype: int """ return self.stack.pop() def hasNext(self): """ :rtype: bool """ while self.list or self.stack: if not self.stack: self.stack.append(self.list.pop(0)) while self.stack and not self.stack[-1].isInteger(): top = self.stack.pop().getList() for e in top[::-1]: self.stack.append(e) if self.stack and self.stack[-1].isInteger(): return True return False