def test(self): solution = Solution() tree1 = TreeNode(1) tree1.left = TreeNode(0) tree1.right = TreeNode(2) tree1output = TreeNode(1) tree1output.right = TreeNode(2) self.assertEqual( assertTreeNodeEqual(solution.trimBST(tree1, 1, 2), tree1output), True)
def test(self): solution = Solution() treeNode1 = TreeNode(1) treeNode1.right = TreeNode(0) treeNode1.right.left = TreeNode(0) treeNode1.right.right = TreeNode(1) treeNode11 = TreeNode(1) treeNode11.right = TreeNode(0) treeNode11.right.right = TreeNode(1) self.assertEqual(assertTreeNodeEqual( solution.pruneTree(treeNode1), treeNode11), True)
def test(self): solution = Solution() rootTreeNode1 = TreeNode(6) rootTreeNode1.left = TreeNode(3) rootTreeNode1.left.right = TreeNode(2) rootTreeNode1.left.right.right = TreeNode(1) rootTreeNode1.right = TreeNode(5) rootTreeNode1.right.left = TreeNode(0) self.assertTrue( assertTreeNodeEqual( solution.constructMaximumBinaryTree([3, 2, 1, 6, 0, 5]), rootTreeNode1))
def test(self): solution = Solution() inTreeNode1 = TreeNode(4) inTreeNode1.left = TreeNode(2) inTreeNode1.right = TreeNode(7) inTreeNode1.left.left = TreeNode(1) inTreeNode1.left.right = TreeNode(3) outTreeNode1 = TreeNode(4) outTreeNode1.left = TreeNode(2) outTreeNode1.right = TreeNode(7) outTreeNode1.left.left = TreeNode(1) outTreeNode1.left.right = TreeNode(3) outTreeNode1.right.left = TreeNode(5) self.assertEqual( assertTreeNodeEqual(solution.insertIntoBST(inTreeNode1, 5), outTreeNode1), True)
def test(self): solution = Solution() root = TreeNode(4) root.left = TreeNode(2) root.left.left = TreeNode(3) root.left.right = TreeNode(1) root.right = TreeNode(6) root.right.left = TreeNode(5) newRoot = TreeNode(4) newRoot.left = TreeNode(1) newRoot.left.left = TreeNode(2) newRoot.left.left.left = TreeNode(3) newRoot.left.left.right = TreeNode(1) newRoot.right = TreeNode(1) newRoot.right.right = TreeNode(6) newRoot.right.right.left = TreeNode(5) self.assertTrue( assertTreeNodeEqual(solution.addOneRow(root, 1, 2), newRoot))