@@ -0,0 +1,942 @@
+package others.algorithm;%0A%0Aimport org.junit.Test;%0A%0A/**%0A */%0Apublic class DeleteSubTree %7B%0A%0A    @Test%0A    public void testDelete() %7B%0A        int%5B%5D tree = %7B1, -1, 1, 0, 2, 4, 3, 4, 4%7D;%0A        deleteSubtree(tree, 2);%0A    %7D%0A%0A    public void deleteSubtree(int%5B%5D tree, int node) %7B%0A        int n = tree.length;%0A        Boolean%5B%5D memo = new Boolean%5Bn%5D;%0A        memo%5Bnode%5D = true;%0A        for (int i = 0; i %3C n; i++) %7B%0A            dfs(memo, tree, i);%0A        %7D%0A        print(memo, tree);%0A    %7D%0A%0A    private boolean dfs(Boolean%5B%5D memo, int%5B%5D tree, int node) %7B%0A        if (node == -1) return false;%0A        if (memo%5Bnode%5D != null) return memo%5Bnode%5D;%0A%0A        memo%5Bnode%5D = dfs(memo, tree, tree%5Bnode%5D);%0A        return memo%5Bnode%5D;%0A    %7D%0A%0A    private void print(Boolean%5B%5D memo, int%5B%5D tree) %7B%0A        for (int i = 0; i %3C tree.length; i++) %7B%0A            if (!memo%5Bi%5D) %7B%0A                System.out.println(tree%5Bi%5D + %22 %3C-%22 + i);%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

delete subtree