public void Test3() { int[] preTree = { 1, 2, 4, 7, 3, 5, 6, 8 }; int[] midTree = { 4, 7, 2, 1, 5, 3, 8, 6 }; TreeNode tree = Coding004.Tree(preTree.ToList(), midTree.ToList()); int[] preTree2 = { 2, 4, 7 }; int[] midTree2 = { 4, 7, 2 }; TreeNode child = Coding004.Tree(preTree2.ToList(), midTree2.ToList()); Assert.True(Coding017.HasSubTree(tree, child)); }
public void Right() { int[] preTree = { 1, 2, 3 }; int[] midTree = { 3, 2, 1 }; TreeNode tree = Coding004.Tree(preTree.ToList(), midTree.ToList()); int[] preTree2 = { 1, 2, 3 }; int[] midTree2 = { 2, 1 }; TreeNode child = Coding004.Tree(preTree2.ToList(), midTree2.ToList()); Assert.True(Coding017.HasSubTree(tree, child)); }
public void Test1() { int[] preTree = { 1, 2, 4, 7, 3, 5, 6, 8 }; //前序 int[] midTree = { 4, 7, 2, 1, 5, 3, 8, 6 }; //中序 TreeNode tree = Coding004.Tree(preTree.ToList(), midTree.ToList()); int[] preTree2 = { 1, 2, 4, 7, 3, 5, 6, 8 }; int[] midTree2 = { 4, 7, 2, 1, 5, 3, 8, 6 }; TreeNode child = Coding004.Tree(preTree2.ToList(), midTree2.ToList()); Assert.True(Coding017.HasSubTree(tree, child)); int[] preTree3 = { 1, 2, 4, 7, 3, 5, 9, 8 }; int[] midTree3 = { 4, 7, 2, 1, 5, 3, 8, 9 }; TreeNode child3 = Coding004.Tree(preTree3.ToList(), midTree3.ToList()); Assert.False(Coding017.HasSubTree(tree, child3)); }