bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 341. Flatten Nested List Iterator

341. Flatten Nested List Iterator

Leetcode Solutions

Approach: Stack

  1. Initialize a stack with the input nestedList reversed.
  2. Implement hasNext() to: a. While the stack is not empty and the top is not an integer, pop the top list, reverse it, and push its elements onto the stack. b. Return true if the stack is not empty, false otherwise.
  3. Implement next() to call hasNext() and if true, pop and return the top integer from the stack.
UML Thumbnail

Approach: Make a Flat List with Recursion

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR