码迷,mamicode.com
首页 >  
搜索关键字:bst    ( 4557个结果
Kth Smallest Element in a BST
该题的思路很简单,就是对BST进行先序遍历,找到第k个数的时候返回。这里借助栈用迭代实现,递归的代码更简单,没有尝试。 class Solution { public: int kthSmallest(TreeNode* root, int k) { stack cache; TreeNode *point = root; TreeNode...
分类:其他好文   时间:2015-07-12 17:27:38    阅读次数:85
【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 thedefinition of LCA on Wikipedia: ...
分类:其他好文   时间:2015-07-12 17:13:07    阅读次数:101
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 nodes with keys less than the node's k...
分类:其他好文   时间:2015-07-12 15:49:25    阅读次数:118
二叉搜索树(BST)
1、什么样的二叉树是二叉搜索树? 答:对于树中的结点X,它的左子树中的项均小于X中的项,它的右子树中的项均大于中的项。2、性质 性质1:二叉查找树的平均深度是O(logN); 性质2:从根节点一直往左走,直至无左路可走,既得最小元素; 性质3:从根节点一直往右走,直至无右路可走,既得最大元素...
分类:其他好文   时间:2015-07-12 15:36:44    阅读次数:103
[LeetCode] 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 thedefinition of LCA on Wikipedia: ...
分类:其他好文   时间:2015-07-12 15:36:05    阅读次数:99
[LeetCode] 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 thedefinition of LCA on Wikipedia: ...
分类:其他好文   时间:2015-07-12 11:07:12    阅读次数:170
Lowest Common Ancestor of Binary (Search) Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
分类:其他好文   时间:2015-07-12 06:58:48    阅读次数:88
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 between two...
分类:其他好文   时间:2015-07-11 22:56:23    阅读次数:386
[LeetCode] Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Ac...
分类:其他好文   时间:2015-07-11 18:21:07    阅读次数:121
【LeetCode】235. Lowest Common Ancestor of a Binary Search Tree (2 solutions)
Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Ac...
分类:其他好文   时间:2015-07-11 18:03:46    阅读次数:137
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!