zl程序教程

binary search tree

  • [Algorithm] Delete a node from Binary Search Tree

    [Algorithm] Delete a node from Binary Search Tree

    The solution for the problem can be divided into three cases: case 1: if the delete node is leaf node, then we can simply remove it case 2: if the delete node is has single side or substree   ca

    日期 2023-06-12 10:48:40     
  • [Algorithm] Delete a node from Binary Search Tree

    [Algorithm] Delete a node from Binary Search Tree

    The solution for the problem can be divided into three cases: case 1: if the delete node is leaf node, then we can simply remove it case 2: if the delete node is has single side or substree   ca

    日期 2023-06-12 10:48:40     
  • Unique Binary Search Trees II -- LeetCode

    Unique Binary Search Trees II -- LeetCode

    原题链接: http://oj.leetcode.com/problems/unique-binary-search-trees-ii/  这道题是求解全部可行的二叉查找树,从Unique Binary Search Trees中我们已经知道,可行的二叉查找树的数量是对应的卡特兰数,不是一个多项式时间的数量级,所以我们要求解全部的树,自然是不能多项式时间内完毕的了。算法

    日期 2023-06-12 10:48:40     
  • [LeetCode] 108. Convert Sorted Array to Binary Search Tree ☆(升序数组转换成一个平衡二叉树)

    [LeetCode] 108. Convert Sorted Array to Binary Search Tree ☆(升序数组转换成一个平衡二叉树)

    108. Convert Sorted Array to Binary Search Tree 描述 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is

    日期 2023-06-12 10:48:40     
  • Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

    Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

    Pat1043代码 题目描写叙述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the

    日期 2023-06-12 10:48:40     
  • PAT 1043 Is It a Binary Search Tree[二叉树][难]

    PAT 1043 Is It a Binary Search Tree[二叉树][难]

    1043 Is It a Binary Search Tree(25 分) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nod

    日期 2023-06-12 10:48:40     
  • leetcode 235. Lowest Common Ancestor of a Binary Search Tree

    leetcode 235. Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee

    日期 2023-06-12 10:48:40     
  • leetcode 669. Trim a Binary Search Tree

    leetcode 669. Trim a Binary Search Tree

    Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the

    日期 2023-06-12 10:48:40     
  • Lintcode: Remove Node in Binary Search Tree

    Lintcode: Remove Node in Binary Search Tree

    iven a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no such a node with given value in the binary search tree, do nothing. You should ke

    日期 2023-06-12 10:48:40     
  • Leetcode: Closest Binary Search Tree Value II

    Leetcode: Closest Binary Search Tree Value II

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target. Note: Given target value is a floating point. You may assume k is always valid, tha

    日期 2023-06-12 10:48:40     
  • Leetcode: Verify Preorder Sequence in Binary Search Tree

    Leetcode: Verify Preorder Sequence in Binary Search Tree

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree. You may assume each number in the sequence is unique. Follow up: Could you do it us

    日期 2023-06-12 10:48:40     
  • Lintcode: Insert Node in a Binary Search Tree

    Lintcode: Insert Node in a Binary Search Tree

    Given a binary search tree and a new tree node, insert the node into the tree. You should keep the tree still be a valid binary search tree. Example Given binary search tree as follow: 2

    日期 2023-06-12 10:48:40     
  • Lintcode: Search Range in Binary Search Tree

    Lintcode: Search Range in Binary Search Tree

    Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x such that k1<=x<=k2 and x is a key of gi

    日期 2023-06-12 10:48:40     
  • Leetcode: Binary Search Tree Iterator

    Leetcode: Binary Search Tree Iterator

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. Note: next() a

    日期 2023-06-12 10:48:40     
  • leetcode第一刷_Convert Sorted Array to Binary Search Tree

    leetcode第一刷_Convert Sorted Array to Binary Search Tree

    晕。竟然另一样的一道题。换成sorted array的话。找到中间位置更加方便了。 TreeNode *sortTree(vector<int> &num, int start, int len){ if(len <= 0) return NULL; int middle = len/2; TreeNode *root = new Tr

    日期 2023-06-12 10:48:40     
  • 1064 Complete Binary Search Tree (30 分)【难度: 一般 / 知识点: 完全二叉搜索树】

    1064 Complete Binary Search Tree (30 分)【难度: 一般 / 知识点: 完全二叉搜索树】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805407749357568 二叉搜索数的中序遍历是有序的。故先将权值排序。 然后中序建树。因为

    日期 2023-06-12 10:48:40     
  • [LeetCode] Convert Sorted Array to Binary Search Tree

    [LeetCode] Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST.   Hide Tags  Tree Depth-first Search     方法一:递归,也是dfs   /**

    日期 2023-06-12 10:48:40     
  • [LeetCode] Unique Binary Search Trees

    [LeetCode] Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST's. 1 3

    日期 2023-06-12 10:48:40     
  • 【LeetCode】173. Binary Search Tree Iterator (2 solutions)

    【LeetCode】173. Binary Search Tree Iterator (2 solutions)

    Binary Search Tree Iterator Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smalles

    日期 2023-06-12 10:48:40     
  • LeetCode:Unique Binary Search Trees

    LeetCode:Unique Binary Search Trees

    问题描写叙述: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1

    日期 2023-06-12 10:48:40     
  • [LeetCode] Trim a Binary Search Tree 修剪一棵二叉搜索树

    [LeetCode] Trim a Binary Search Tree 修剪一棵二叉搜索树

      Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to chang

    日期 2023-06-12 10:48:40     
  • [LeetCode] 96. Unique Binary Search Trees 独一无二的二叉搜索树

    [LeetCode] 96. Unique Binary Search Trees 独一无二的二叉搜索树

      Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 un

    日期 2023-06-12 10:48:40     
  • [LeetCode] 99. Recover Binary Search Tree 复原二叉搜索树

    [LeetCode] 99. Recover Binary Search Tree 复原二叉搜索树

      Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Example 1: Input: [1,3,null,null,2]   1   /  3   \ &nb

    日期 2023-06-12 10:48:40     
  • [LeetCode]  Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树

    [LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树

      Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in whi

    日期 2023-06-12 10:48:40     
  • [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树

    [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树

      Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth

    日期 2023-06-12 10:48:40     
  • 1043 Is It a Binary Search Tree

    1043 Is It a Binary Search Tree

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right su

    日期 2023-06-12 10:48:40     
  • 96. Unique Binary Search Trees

    96. Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 unique BS

    日期 2023-06-12 10:48:40     
  • Convert Sorted Array to Binary Search Tree

    Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of

    日期 2023-06-12 10:48:40     
  • Insert into a Binary Search Tree

    Insert into a Binary Search Tree

    Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed t

    日期 2023-06-12 10:48:40     
  • leetcode 669. Trim a Binary Search Tree 修剪二叉搜索树 (简单)

    leetcode 669. Trim a Binary Search Tree 修剪二叉搜索树 (简单)

    一、题目大意 给你二叉搜索树的根节点 root ,同时给定最小边界low 和最大边界 high。通过修剪二叉搜索树,使得所有节点的值在[low, high]中。修剪树 不应该 改变保留在树中的元

    日期 2023-06-12 10:48:40