← 返回 apple 的题目列表Lazy Binary Tree Inorder Iterator
类型:qbank
Design an iterator over a binary tree that returns nodes in inorder sequence without precomputing all values. The follow-up asks about multiple iterators and thread safety.
Examples
Example 1:
Input: ["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"] [[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]
Output: [null, 3, 7, true, 9, true, 15, true, 20, false]
Constraints
The number of nodes in the tree is in the range [1, 10^5].
0 <= Node.val <= 10^6
At most 10^5 calls will be made to hasNext, and next.