def main(*args): preorder = [3, 9, 20, 15, 7] inorder = [9, 3, 15, 20, 7] result = Solution().buildTree(preorder, inorder) BTreeHelper.pretty_print(result) print(result)
def main(*args): tree_array = [1, 2] value = 22 root = BTreeHelper.list_to_tree(tree_array) BTreeHelper.pretty_print(root) result = Solution().hasPathSum(root, value) print(result)
def main(*args): tree_array = [10, 5, 14, 3, 7, None, None, 2, 4] none_tree = [] root = BTreeHelper.list_to_tree(none_tree) BTreeHelper.pretty_print(root) itr = BSTIterator(root) while itr.hasNext(): print(itr.next())
def main(*args): tree_array = [10, 5, 15, 2, 6, 12, None, None, None, None, 7, None, 13] root = BTreeHelper.list_to_tree(tree_array) BTreeHelper.pretty_print(root) solution = Solution() data = solution.serialize(root) print(data) node = solution.deserialize(data) print(BTreeHelper.pretty_print(node))
def main(*args): inorder = [9, 3, 15, 20, 7] postorder = [9, 15, 7, 20, 3] #inorder = [1, 2, 3] #postorder = [3, 2, 1] #inorder = [2, 1] #postorder = [2, 1] result = Solution().buildTree(inorder, postorder) BTreeHelper.pretty_print(result) print(result)
def main(*args): tree_array = [1, 0] root = BTreeHelper.list_to_tree(tree_array) val = 1 result = Solution().insertIntoBST(root, 2) BTreeHelper.pretty_print(result)
def main(*args): tree_array = [0, 1] root = BTreeHelper.list_to_tree(tree_array) result = Solution().isValidBST(root) print(result)
def main(*args): tree_array = [5, 3, 6, 2, 4, None, 7] root = BTreeHelper.list_to_tree(tree_array) BTreeHelper.pretty_print(root) result = Solution().deleteNode(root, 3) BTreeHelper.pretty_print(result)
def main(*args): tree_array = [5, 1, 2, 0, None, 3, 4, None, None, 6] root = BTreeHelper.list_to_tree(tree_array) BTreeHelper.pretty_print(root) result = Solution().inorderTraversal(root) print(result)
def main(*args): tree_array = [3, 9, 20, None, None, 15, 7] root = BTreeHelper.list_to_tree(tree_array) BTreeHelper.pretty_print(root) result = Solution().levelOrder(root) print(result)
def main(*args): tree_array = [1, 2, 3, 4, None, None, 5] root = BTreeHelper.list_to_tree(tree_array) BTreeHelper.pretty_print(root) result = Solution().maxDepth(root) print(result)