原文链接: https://leetcode-cn.com/problems/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. Examp…
标签详情
二叉搜索树 分类
原文链接: https://leetcode-cn.com/problems/unique-binary-search-trees 英文原文Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n. Example 1: Input: n = 3 Output: 5 E…
原文链接: https://leetcode-cn.com/problems/validate-binary-search-tree 英文原文Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys l…
原文链接: https://leetcode-cn.com/problems/recover-binary-search-tree 英文原文You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure. Ex…
原文链接: https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree 英文原文Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a…
原文链接: https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree 英文原文Given the head of 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 …
原文链接: https://leetcode-cn.com/problems/binary-search-tree-iterator 英文原文Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTI…
原文链接: https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst 英文原文Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. Example 1: Input: root = [3,1,4,n…
原文链接: https://leetcode-cn.com/problems/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: “T…
原文链接: https://leetcode-cn.com/problems/serialize-and-deserialize-bst 英文原文Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection li…
原文链接: https://leetcode-cn.com/problems/delete-node-in-a-bst 英文原文Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can b…
原文链接: https://leetcode-cn.com/problems/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, re…
原文链接: https://leetcode-cn.com/problems/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,…
原文链接: https://leetcode-cn.com/problems/convert-bst-to-greater-tree 英文原文Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater …
原文链接: https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst 英文原文Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target. Example 1: Input: …
原文链接: https://leetcode-cn.com/problems/trim-a-binary-search-tree 英文原文Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should no…
原文链接: https://leetcode-cn.com/problems/search-in-a-binary-search-tree 英文原文You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node.…
原文链接: https://leetcode-cn.com/problems/insert-into-a-binary-search-tree 英文原文You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the …
原文链接: https://leetcode-cn.com/problems/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 cla…
原文链接: https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes 英文原文Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree. Example 1: Input: root = [4,2,6,1,3] …
原文链接: https://leetcode-cn.com/problems/increasing-order-search-tree 英文原文Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and onl…
原文链接: https://leetcode-cn.com/problems/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…
原文链接: https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal 英文原文Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root. …
原文链接: https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree 英文原文Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all ke…
原文链接: https://leetcode-cn.com/problems/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…
原文链接: https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees 英文原文Given two binary search trees root1 and root2. Return a list containing all the integers from both trees sorted in ascending order. Example 1: Input: root1 = [2,1,4], …
原文链接: https://leetcode-cn.com/problems/maximum-sum-bst-in-binary-tree 英文原文Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST). Assume a BST is defined as follows: The left subtree of a…
原文链接: https://leetcode-cn.com/problems/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 nu…
原文链接: https://leetcode-cn.com/problems/minimum-height-tree-lcci 英文原文Given a sorted (increasing order) array with unique integer elements, write an algo­rithm to create a binary search tree with minimal height. Example: Given sorted array: [-10,-3…
原文链接: https://leetcode-cn.com/problems/legal-binary-search-tree-lcci 英文原文Implement a function to check if a binary tree is a binary search tree. Example 1: Input: 2 / \ 1 3 Output: true Example 2: Input: 5 / \ 1 4 / \ 3 6 Output: false Explanation: I…
1 / 2