Leetcode-cn.com 2022-06-02
🟡 450.delete-node-in-a-bst
🏷️ Tags
#tree #binary_search_tree #binary_tree
Description
给定一个二叉搜索树的根节点 root 和一个值 key,删除二叉搜索树中的 key 对应的节点,并保证二叉搜索树的性质不变。返回二叉搜索树(有可能被更新)的根节点的引用。
一般来说,删除节点可分为两个步骤:
首先找到需要删除的节点;
如果找到了,删除它。
Example
🟡 450.delete-node-in-a-bst
🏷️ Tags
#tree #binary_search_tree #binary_tree
Description
给定一个二叉搜索树的根节点 root 和一个值 key,删除二叉搜索树中的 key 对应的节点,并保证二叉搜索树的性质不变。返回二叉搜索树(有可能被更新)的根节点的引用。
一般来说,删除节点可分为两个步骤:
首先找到需要删除的节点;
如果找到了,删除它。
Example
输入:root = [5,3,6,2,4,null,7], key = 3
输出:[5,4,6,2,null,null,7]
解释:给定需要删除的节点值是 3,所以我们首先找到 3 这个节点,然后删除它。
一个正确的答案是 [5,4,6,2,null,null,7], 如下图所示。
另一个正确答案是 [5,2,6,null,4,null,7]。
108.convert-sorted-array-to-binary-search-tree.pdf
103.1 KB
leetcode.com 2022-08-10
🟢108.convert-sorted-array-to-binary-search-tree
🏷️ Tags
#array #divide_and_conquer #tree #binary_search_tree #binary_tree
🟢108.convert-sorted-array-to-binary-search-tree
🏷️ Tags
#array #divide_and_conquer #tree #binary_search_tree #binary_tree
98.validate-binary-search-tree.pdf
87.7 KB
leetcode.com 2022-08-11
🟡98.validate-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟡98.validate-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
235.lowest-common-ancestor-of-a-binary-search-tree.pdf
66.9 KB
leetcode.com 2022-08-12
🟢235.lowest-common-ancestor-of-a-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟢235.lowest-common-ancestor-of-a-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
669.trim-a-binary-search-tree.pdf
114.5 KB
leetcode.cn 2022-09-10
🟡669.trim-a-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟡669.trim-a-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
653.two-sum-iv-input-is-a-bst.pdf
109.5 KB
leetcode.com 2022-10-09
🟢653.two-sum-iv-input-is-a-bst
🏷️ Tags
#hash_table #two_pointers #tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
🟢653.two-sum-iv-input-is-a-bst
🏷️ Tags
#hash_table #two_pointers #tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
938.range-sum-of-bst.pdf
110.9 KB
leetcode.com 2022-12-07
🟢938.range-sum-of-bst
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟢938.range-sum-of-bst
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
783.minimum-distance-between-bst-nodes.pdf
86.4 KB
leetcode.com 2023-02-17
🟢783.minimum-distance-between-bst-nodes
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
🟢783.minimum-distance-between-bst-nodes
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
109.convert-sorted-list-to-binary-search-tree.pdf
106.1 KB
leetcode.com 2023-03-11
🟡109.convert-sorted-list-to-binary-search-tree
🏷️ Tags
#linked_list #divide_and_conquer #tree #binary_search_tree #binary_tree
🟡109.convert-sorted-list-to-binary-search-tree
🏷️ Tags
#linked_list #divide_and_conquer #tree #binary_search_tree #binary_tree
leetcode.cn 2023-05-20
🔴1373.maximum-sum-bst-in-binary-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #dynamic_programming #binary_tree
🔴1373.maximum-sum-bst-in-binary-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #dynamic_programming #binary_tree
Telegraph
maximum-sum-bst-in-binary-tree
给你一棵以 root 为根的 二叉树 ,请你返回 任意 二叉搜索子树的最大键值和。 二叉搜索树的定义如下:
leetcode.com 2023-05-23
🟢703.kth-largest-element-in-a-stream
🏷️ Tags
#tree #design #binary_search_tree #binary_tree #data_stream #heap_priority_queue
🟢703.kth-largest-element-in-a-stream
🏷️ Tags
#tree #design #binary_search_tree #binary_tree #data_stream #heap_priority_queue
Telegraph
kth-largest-element-in-a-stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest class:
leetcode.com 2023-06-14
🟢530.minimum-absolute-difference-in-bst
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
🟢530.minimum-absolute-difference-in-bst
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
Telegraph
minimum-absolute-difference-in-bst
Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree. Example 1: Input: root = [4,2,6,1,3] Output: 1 Example 2: Input: root = [1,0,48,null,null,12,49] Output: 1 …
leetcode.com 2023-06-16
🔴1569.number-of-ways-to-reorder-array-to-get-same-bst
🏷️ Tags
#tree #union_find #binary_search_tree #memoization #array #math #divide_and_conquer #dynamic_programming #binary_tree #combinatorics
🔴1569.number-of-ways-to-reorder-array-to-get-same-bst
🏷️ Tags
#tree #union_find #binary_search_tree #memoization #array #math #divide_and_conquer #dynamic_programming #binary_tree #combinatorics
Telegraph
number-of-ways-to-reorder-array-to-get-same-bst
Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that…
leetcode.com 2023-08-05
🟡95.unique-binary-search-trees-ii
🏷️ Tags
#tree #binary_search_tree #dynamic_programming #backtracking #binary_tree
🟡95.unique-binary-search-trees-ii
🏷️ Tags
#tree #binary_search_tree #dynamic_programming #backtracking #binary_tree
Telegraph
unique-binary-search-trees-ii
Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order. Example 1: Input: n = 3 Output: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null…
leetcode.cn 2023-09-04
🟡449.serialize-and-deserialize-bst
🏷️ Tags
#tree #depth_first_search #breadth_first_search #design #binary_search_tree #string #binary_tree
🟡449.serialize-and-deserialize-bst
🏷️ Tags
#tree #depth_first_search #breadth_first_search #design #binary_search_tree #string #binary_tree
Telegraph
serialize-and-deserialize-bst
序列化是将数据结构或对象转换为一系列位的过程,以便它可以存储在文件或内存缓冲区中,或通过网络连接链路传输,以便稍后在同一个或另一个计算机环境中重建。 设计一个算法来序列化和反序列化 二叉搜索树 。 对序列化/反序列化算法的工作方式没有限制。 您只需确保二叉搜索树可以序列化为字符串,并且可以将该字符串反序列化为最初的二叉搜索树。 编码的字符串应尽可能紧凑。 示例 1: 输入:root = [2,1,3] 输出:[2,1,3] 示例 2: 输入:root = [] 输出:[] 提示:
leetcode.com 2023-11-01
🟢501.find-mode-in-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟢501.find-mode-in-binary-search-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
Telegraph
find-mode-in-binary-search-tree
Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it. If the tree has more than one mode, return them in any order. Assume a BST is defined as follows:
👍1
leetcode.cn 2023-12-04
🟡1038.binary-search-tree-to-greater-sum-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟡1038.binary-search-tree-to-greater-sum-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
Telegraph
binary-search-tree-to-greater-sum-tree
给定一个二叉搜索树 root (BST),请将它的每个节点的值替换成树中大于或者等于该节点值的所有节点值之和。 提醒一下, 二叉搜索树 满足下列约束条件:
leetcode.com 2024-01-08
🟢938.range-sum-of-bst
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟢938.range-sum-of-bst
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
Telegraph
range-sum-of-bst
Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. Example 1: Input: root = [10,5,15,3,7,null,18], low = 7, high = 15 Output: 32 Explanation:…
leetcode.cn 2026-02-09
🟡1382.balance-a-binary-search-tree
🏷️ Tags
#greedy #tree #depth_first_search #binary_search_tree #divide_and_conquer #binary_tree
🟡1382.balance-a-binary-search-tree
🏷️ Tags
#greedy #tree #depth_first_search #binary_search_tree #divide_and_conquer #binary_tree
Telegraph
balance-a-binary-search-tree
给你一棵二叉搜索树,请你返回一棵 平衡后 的二叉搜索树,新生成的树应该与原来的树有着相同的节点值。如果有多种构造方法,请你返回任意一种。 如果一棵二叉搜索树中,每个节点的两棵子树高度差不超过 1 ,我们就称这棵二叉搜索树是 平衡的 。 示例 1: 输入:root = [1,null,2,null,3,null,4,null,null] 输出:[2,1,3,null,null,null,4] 解释:这不是唯一的正确答案,[3,1,4,null,2,null,null] 也是一个可行的构造方案。 示例 2:…
leetcode.com 2026-02-09
🟡1382.balance-a-binary-search-tree
🏷️ Tags
#greedy #tree #depth_first_search #binary_search_tree #divide_and_conquer #binary_tree
🟡1382.balance-a-binary-search-tree
🏷️ Tags
#greedy #tree #depth_first_search #binary_search_tree #divide_and_conquer #binary_tree
Telegraph
balance-a-binary-search-tree
Given the root of a binary search tree, return a balanced binary search tree with the same node values. If there is more than one answer, return any of them. A binary search tree is balanced if the depth of the two subtrees of every node never differs by…