标签:
完全没有想法
实际上是in order traversal而已
public class BSTIterator { public TreeNode crt; public Stack<TreeNode> st = new Stack<TreeNode>(); public BSTIterator(TreeNode root) { crt = root; } /** @return whether we have a next smallest number */ public boolean hasNext() { return (crt!=null||!st.isEmpty()); } /** @return the next smallest number */ public int next() { while(crt!=null){ st.push(crt); crt = crt.left; } crt = st.pop(); int res =crt.val; crt = crt.right; return res; } }
标签:
原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4582277.html