Error:
do not how to do: actually it use iterate inorder for a tree, since inorder for BST is the sorted array of the tree. Also, since we only allow to use O(h) memory, we cannot recursive inorder and store it use array/vector, since it has O(n) memory. So we need to iterate the BST, it has three step:
1. create a stack
2. push current node and move cur = cur->left until it null
3. print the top of stack, and move cur = cur->right
4. repeat it until stack is empty
leetcode-173-Binary Search Tree Iterator
最新推荐文章于 2022-06-10 17:57:38 发布