Lowest Common Ancestor of a Binary Search TreeTotal Accepted:7402Total Submissions:19069My SubmissionsQuestionSolutionGiven a binary search tree (BST)...
分类:
编程语言 时间:
2015-07-19 11:39:59
阅读次数:
153
做到这个题才发现之前做的关于二叉检索树的写复杂了,其实可以直接根据二叉检索树的特点进行判断(从树根开始,某一节点的值大于待搜的两个节点则在左边找,小于待搜的两个节点则在右边找,否则返回该节点即可)。这道题倒是必须用DFS来解决。
class Solution {
public:
//DFS代码
void findNode(TreeNode* root, TreeNode* toF...
分类:
其他好文 时间:
2015-07-19 10:16:49
阅读次数:
113
Lowest Common Ancestor of a Binary TreeTotal Accepted:4228Total Submissions:15884My SubmissionsQuestionSolutionGiven a binary tree, find the lowest co...
分类:
其他好文 时间:
2015-07-19 09:57:53
阅读次数:
87
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...
分类:
其他好文 时间:
2015-07-18 11:04:32
阅读次数:
97
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined
between two node...
分类:
其他好文 时间:
2015-07-17 12:14:36
阅读次数:
75
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-17 11:20:19
阅读次数:
115
Consider the following "magic" 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.
Working clockwise, and starting from the group of three with the numerically lowest exte...
分类:
其他好文 时间:
2015-07-17 10:06:11
阅读次数:
231
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 Wiki...
分类:
其他好文 时间:
2015-07-16 22:26:18
阅读次数:
125
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
betw...
分类:
其他好文 时间:
2015-07-16 16:50:11
阅读次数:
98
题目地址:点击打开链接
解法一:对于深度过高的case过不了。
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NU...
分类:
其他好文 时间:
2015-07-15 22:53:52
阅读次数:
163