package leetcode;

/**
 * https://leetcode.com/problems/increasing-order-search-tree/
 */
public class Problem897 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public TreeNode increasingBST(TreeNode root) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem897 prob = new Problem897();
        TreeNode root = new TreeNode(5);
        root.left = new TreeNode(3);
        root.left.left = new TreeNode(2);
        root.left.right = new TreeNode(4);
        root.left.left.left = new TreeNode(1);
        root.right = new TreeNode(6);
        root.right.right = new TreeNode(8);
        root.right.right.left = new TreeNode(7);
        root.right.right.right = new TreeNode(9);

        System.out.println(prob.increasingBST(root));
    }
}

@@ -336,36 +336,905 @@
     
-// TODO%0A        return null;
+TreeNodeRef ref = new TreeNodeRef();%0A        increasingBST(root, ref);%0A        return ref.root;%0A    %7D%0A%0A    private static class TreeNodeRef %7B%0A        private TreeNode root;%0A        private TreeNode node;%0A    %7D%0A%0A    private static void increasingBST(TreeNode root, TreeNodeRef ref) %7B%0A        if (root == null) %7B%0A            return;%0A        %7D%0A        increasingBST(root.left, ref);%0A        if (ref.root == null) %7B%0A            ref.root = root;%0A            ref.node = root;%0A        %7D else %7B%0A            ref.node.left = null;%0A            ref.node.right = root;%0A            ref.node = root;%0A        %7D%0A        increasingBST(root.right, ref);%0A    %7D%0A%0A    private static void print(TreeNode node) %7B%0A        for (TreeNode n = node; n != null; n = n.right) %7B%0A            if (n.left != null) %7B%0A                throw new RuntimeException(%22Wrong!%22);%0A            %7D%0A            System.out.println(n.val);%0A        %7D
 %0A   
@@ -1726,34 +1726,62 @@
         
-System.out.
+print(prob.increasingBST(root));%0A        
 print
-ln
 (prob.in
@@ -1784,32 +1784,43 @@
 b.increasingBST(
-root
+new TreeNode(1)
 ));%0A    %7D%0A%7D%0A

Update problem 897