二叉搜索树
文章平均质量分 77
jmspan
这个作者很懒,什么都没留下…
展开
-
LeetCode 230. Kth Smallest Element in a BST(二叉搜索树中的第K个元素)
原题网址:https://leetcode.com/problems/kth-smallest-element-in-a-bst/Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is原创 2016-04-05 11:16:32 · 1420 阅读 · 0 评论 -
LeetCode 449. Serialize and Deserialize BST
原题网址:https://leetcode.com/problems/serialize-and-deserialize-bst/Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file原创 2017-01-04 06:39:45 · 846 阅读 · 0 评论 -
红黑树
红黑树的两种基本操作做旋转和右旋转,LEFT_ROTATE(x)和RIGHT_ROTATE(x)分别表示以x为支点进行左旋转和右旋转。红黑树的插入操作以插入点为当前点(z),检查是否满足红黑树规则,如果不满足则调整,直至完全满足为止。根据当前点z的父节点和叔叔节点的颜色,可以分为均为红色以及叔叔节点为黑色的情况,而根据当前节点是父节点的做节点还是右节点分为两种情况。原创 2016-08-01 06:51:26 · 510 阅读 · 0 评论 -
LeetCode 315. Count of Smaller Numbers After Self (逆序数对)
原题网址:https://leetcode.com/problems/count-of-smaller-numbers-after-self/You are given an integer array nums and you have to return a new counts array. The counts array has the property where coun原创 2016-04-22 13:21:32 · 7408 阅读 · 2 评论 -
LeetCode 316. Remove Duplicate Letters(删除重复字母)
原题网址:https://leetcode.com/problems/remove-duplicate-letters/Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You mus原创 2016-04-23 05:51:58 · 2194 阅读 · 1 评论 -
LeetCode 99. Recover Binary Search Tree(修复二叉搜索树)
原题网址:https://leetcode.com/problems/recover-binary-search-tree/Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A sol原创 2016-05-23 00:39:29 · 610 阅读 · 0 评论 -
LeetCode 285. Inorder Successor in BST
原题网址:https://leetcode.com/problems/inorder-successor-in-bst/Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in原创 2016-04-15 00:35:29 · 1162 阅读 · 0 评论 -
LeetCode 352. Data Stream as Disjoint Intervals(数据流区间)
原题网址:https://leetcode.com/problems/data-stream-as-disjoint-intervals/Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of dis原创 2016-06-16 01:11:36 · 1555 阅读 · 0 评论 -
LeetCode 109. Convert Sorted List to Binary Search Tree(链表到二叉搜索树)
原题网址:https://leetcode.com/problems/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.方法:使用慢指针原创 2016-05-24 00:12:46 · 573 阅读 · 0 评论 -
LeetCode 98. Validate Binary Search Tree(校验二叉搜索树)
原题网址:https://leetcode.com/problems/validate-binary-search-tree/Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtre原创 2016-05-23 00:39:15 · 488 阅读 · 0 评论 -
LeetCode 95. Unique Binary Search Trees II(唯一二叉搜索树)
原题网址:https://leetcode.com/problems/unique-binary-search-trees-ii/Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your原创 2016-05-23 00:35:30 · 484 阅读 · 0 评论 -
LeetCode 333. Largest BST Subtree(最大二叉搜索树)
原题网址:https://leetcode.com/problems/largest-bst-subtree/Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes原创 2016-04-29 13:22:12 · 2205 阅读 · 0 评论 -
LeetCode 272. Closest Binary Search Tree Value II(二叉搜索树查找)
原题网址:https://leetcode.com/problems/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:原创 2016-04-13 06:15:51 · 2029 阅读 · 0 评论 -
LeetCode 327. Count of Range Sum(区间和计数)
原题网址:https://leetcode.com/problems/count-of-range-sum/Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the su原创 2016-04-28 00:32:14 · 3697 阅读 · 0 评论 -
LeetCode 173. Binary Search Tree Iterator(二叉搜索树迭代器)
原题网址:https://leetcode.com/problems/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 ne原创 2016-05-25 01:36:36 · 1476 阅读 · 0 评论 -
LeetCode 270. Closest Binary Search Tree Value(二叉搜索树最接近值查找)
原题网址:https://leetcode.com/problems/closest-binary-search-tree-value/Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:原创 2016-04-13 02:53:19 · 3001 阅读 · 0 评论 -
LeetCode 108. Convert Sorted Array to Binary Search Tree(数组转换为二叉搜索树)
原题网址:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/Given an array where elements are sorted in ascending order, convert it to a height balanced BST.方法:递归,自顶向下。/** *原创 2016-05-24 00:12:53 · 491 阅读 · 0 评论 -
LeetCode 235. Lowest Common Ancestor of a Binary Search Tree(二叉搜索树的最低公共祖先)
原题网址:https://leetcode.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.Accord原创 2016-04-06 06:33:46 · 678 阅读 · 0 评论 -
LeetCode 450. Delete Node in a BST
原题网址:https://leetcode.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 up原创 2017-01-04 08:36:18 · 960 阅读 · 0 评论