← Back to problems Solve on LeetCode →

Flatten Nested List Iterator

LeetCode 341 • Medium • Design

Design an iterator to flatten a nested list of integers.
NestedInteger is either an int or a list of NestedInteger. Use a stack; ensure the top is always an integer before next.

nextO(1)amortized
hasNextO(1)amortized
SpaceO(d)nesting depth
Step0
stack: …
Ready
Press Play or Step.