LC的BST iterator到底要考察什么?# JobHunting - 待字闺中
A*e
1 楼
给的BST节点没有父指针。然后有下面的要求:
Note: next() and hasNext() should run in average O(1) time and uses O(h)
memory, where h is the height of the tree.
试着写了一个版本,直接周游BST,把结果存在数组里,然后hasNext()和next()都是O(
1)和O(1),居然也过了。感觉在作弊。
Note: next() and hasNext() should run in average O(1) time and uses O(h)
memory, where h is the height of the tree.
试着写了一个版本,直接周游BST,把结果存在数组里,然后hasNext()和next()都是O(
1)和O(1),居然也过了。感觉在作弊。