@@ -0,0 +1,811 @@
+import java.util.Stack;%0A%0Apublic class _173BinarySearchTreeIterator %7B%0A%09TreeNode root;%0A%09Stack%3CTreeNode%3E stack = new Stack%3CTreeNode%3E();%0A%0A    public _173BinarySearchTreeIterator(TreeNode root) %7B%0A        this.root = root;%0A        TreeNode tn = root;%0A        while (tn != null) %7B%0A        %09stack.push(tn);%0A        %09tn = tn.left;%0A        %7D%0A    %7D%0A%0A    public boolean hasNext() %7B%0A        return !stack.isEmpty();%0A    %7D%0A%0A    public int next() %7B%0A    %09TreeNode tn = stack.pop();%0A    %09int val = tn.val;%0A        if (tn.right != null) %7B%0A        %09tn = tn.right;%0A        %09while (tn != null) %7B%0A            %09stack.push(tn);%0A            %09tn = tn.left;%0A            %7D%0A        %7D%0A        return val;%0A    %7D%0A    %0A    public class TreeNode %7B%0A    %09int val;%0A    %09TreeNode left;%0A    %09TreeNode right;%0A    %09TreeNode(int x) %7B val = x; %7D%0A    %7D%0A%7D%0A

Add 173 solution