problem
solution
option 1 - STL to store
事先先拜訪過各節點並存下來,再用一個指標指向當前位置
1 | class BSTIterator { |
option 2 - stack
1 | class BSTIterator { |
analysis
- time complexity
O(1)
- space complexity
O(h)
事先先拜訪過各節點並存下來,再用一個指標指向當前位置
1 | class BSTIterator { |
1 | class BSTIterator { |
O(1)
O(h)