Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NestedIterator:
- def __init__(self, nestedList: [NestedInteger]):
- self.stack = []
- for i in reversed(nestedList):
- self.stack.append(i)
- def next(self) -> int:
- return self.stack.pop().getInteger()
- def hasNext(self) -> bool:
- while self.stack:
- top = self.stack[-1]
- if top.isInteger():
- return True
- self.stack.pop()
- for i in reversed(top.getList()):
- self.stack.append(i)
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement